Solved

How can I authenticate to the CrmMetadataService in an IFD environment?

Posted on 2011-03-02
1
584 Views
Last Modified: 2012-06-04
I'm trying to connect to the CrmMetadataService from a custom web service that I am using to run some extensive calculations on data. The environment is CRM 4 installed as an Internet Facing Deployment. I have no trouble using the DiscoverySerbive to issue an authentication token from the CrmService web service. Unfortunately, I'm having trouble configuring the MetaDataService. My Code for the CrmService is as follows:

public static string GetIFDConnection(string organization, string server, string domain, string username, string password, CrmService crmService)
        {
            // Remove any trailing forward slash from the end of the server URL.
            server = server.TrimEnd(new char[] { '/' });

            // Initialize an instance of the CrmDiscoveryService Web service proxy
            CrmDiscoveryService disco = new CrmDiscoveryService();
            disco.Url = server + "/MSCRMServices/2007/SPLA/CrmDiscoveryService.asmx";

            // Retrieve a list of available organizations.
            RetrieveOrganizationsRequest orgRequest = new RetrieveOrganizationsRequest();
            orgRequest.UserId = domain + "\\" + username;
            orgRequest.Password = password;
            RetrieveOrganizationsResponse orgResponse = (RetrieveOrganizationsResponse)disco.Execute(orgRequest);

            // Find the desired organization
            foreach (OrganizationDetail orgdetail in orgResponse.OrganizationDetails)
            {
                if (String.Compare(orgdetail.OrganizationName, organization, true) == 0)
                {
                    //Retrieve the ticket
                    RetrieveCrmTicketRequest ticketRequest = new RetrieveCrmTicketRequest();
                    ticketRequest.OrganizationName = organization;
                    ticketRequest.UserId = domain + "\\" + username;
                    //ticketRequest.UserId = username;
                    ticketRequest.Password = password;
                    RetrieveCrmTicketResponse ticketResponse = (RetrieveCrmTicketResponse)disco.Execute(ticketRequest);

                    // Create the CrmService Web service proxy
                    CrmSdk.CrmAuthenticationToken sdktoken = new CrmSdk.CrmAuthenticationToken();
                    sdktoken.AuthenticationType = 2; // Use IFD Authentication
                    sdktoken.OrganizationName = organization;
                    sdktoken.CrmTicket = ticketResponse.CrmTicket;
                    crmService.CrmAuthenticationTokenValue = sdktoken;
                    return orgdetail.CrmServiceUrl;
                }
            }

Open in new window


I am setting the token and passing back the service endpoint URL. This works great for the CrmService Web service. Can anyone tell me how to do the same thing to configure the MetadataService? Here is what I have so far...

 
public static string GetMetadataIFDConnection(string organization, string server, string domain, string username, string password, CrmService crmService)
        {
            // Remove any trailing forward slash from the end of the server URL.
            server = server.TrimEnd(new char[] { '/' });

            // Initialize an instance of the CrmDiscoveryService Web service proxy
            CrmDiscoveryService disco = new CrmDiscoveryService();
            disco.Url = server + "/MSCRMServices/2007/SPLA/CrmDiscoveryService.asmx";

            // Retrieve a list of available organizations.
            RetrieveOrganizationsRequest orgRequest = new RetrieveOrganizationsRequest();
            orgRequest.UserId = domain + "\\" + username;
            orgRequest.Password = password;
            RetrieveOrganizationsResponse orgResponse = (RetrieveOrganizationsResponse)disco.Execute(orgRequest);

            // Find the desired organization
            foreach (OrganizationDetail orgdetail in orgResponse.OrganizationDetails)
            {
                if (String.Compare(orgdetail.OrganizationName, organization, true) == 0)
                {
                    //Retrieve the ticket
                    RetrieveCrmTicketRequest ticketRequest = new RetrieveCrmTicketRequest();
                    ticketRequest.OrganizationName = organization;
                    ticketRequest.UserId = domain + "\\" + username;
                    //ticketRequest.UserId = username;
                    ticketRequest.Password = password;
                    RetrieveCrmTicketResponse ticketResponse = (RetrieveCrmTicketResponse)disco.Execute(ticketRequest);

                    // Create the CrmService Web service proxy
                    CrmSdk.CrmAuthenticationToken sdktoken = new CrmSdk.CrmAuthenticationToken();
                    sdktoken.AuthenticationType = 2; // Use IFD Authentication
                    sdktoken.OrganizationName = organization;
                    sdktoken.CrmTicket = ticketResponse.CrmTicket;
                    crmService.CrmAuthenticationTokenValue = sdktoken;
                    return orgdetail.CrmMetadataServiceUrl;
                }
            }
            return "";
        }

Open in new window


My thought ws to configure it the same way I did with the CrmService but return the  orgdetail.CrmMetadataServiceUrl instead (see the last lines of the method). I'm still getting a authentication error when trying to contact the MetadataService. Any ideas would be appreciated.

Thanks...
0
Comment
Question by:svcoder
1 Comment
 
LVL 8

Accepted Solution

by:
Aftab_Khateeb earned 500 total points
ID: 35480736
Hi, Have you tried instead of Organisation name the URL of the IFD
for e.g. http://yourServerAddress/yourOrgName/mscrmservices....
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This is a walkthrough guide I wrote whilst upgrading my on-premise MS Dynamics CRM 3.0 deployment to 4.0. This covers the actual installation of the product to a working level for my system, I ran into a lot of issues that the steps below fixed so h…
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question