Solved

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

Posted on 2011-03-02
1
575 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
For cloud, the “train has left the station” and in the Microsoft ERP & CRM world, that means the next generation of enterprise software from Microsoft is here: Dynamics 365 is Microsoft’s new integrated business solution that unifies CRM and ERP fun…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

760 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now