CrmDiscoveryService Web Service

The CrmDiscoveryService Web service can provide a list of organizations and their corresponding Web service endpoint URLs. You use this information to configure the CrmService and MetadataService Web service proxies and call Web service methods that access an organization’s data. The discovery service URL is fixed per installation so that you can programmatically configure solutions for multiple organizations in a single environment.

The discovery Web service is most applicable for the following situations:

  • Large-scale installations of Microsoft Dynamics CRM, where the installation may have the Web service APIs installed on a server different from the Microsoft Dynamics CRM Web server

  • Independent software vendors (ISVs) solutions

More Info

More Info

A multi-tenant installation is one in which multiple CRM organizations are configured against a common set of hardware. Remember that each organization contains a unique database that contains the custom configuration and all the business data. You need the Enterprise edition of Microsoft Dynamics CRM to setup and deploy a multi-tenant deployment.

The CrmDiscoveryService Web service for an on-premise installation is located at http://<crmserver>/mscrmservices/2007/AD/CrmDiscoveryService.asmx, where crmserver is the Microsoft Dynamics CRM Web server.

Note

Note

Microsoft Dynamics CRM Online uses a different URL for the discovery service. If you are working with a Microsoft Dynamics CRM Online implementation, use the following URL instead: https://dev.crm.dynamics.com/MSCRMServices/2007/Passport/CrmDiscoveryService.asmx.

Example 3-2 shows some basic code using the CrmDiscoveryService to retrieve organizations and their API Web service URLs.

Example 3-2. Example using the CrmDiscoveryService

// Create and configure the CrmDiscoveryService Web service proxy.
CrmDiscoveryService discoveryService = new CrmDiscoveryService();
discoveryService.UseDefaultCredentials = true;
discoveryService.Url =
  "http://<servername>/MSCRMServices/2007/AD/CrmDiscoveryService.asmx";

// Retrieve the list of organizations to which the logged-on user belongs.
RetrieveOrganizationsRequest orgRequest = new RetrieveOrganizationsRequest();
RetrieveOrganizationsResponse orgResponse =
    (RetrieveOrganizationsResponse)discoveryService.Execute(orgRequest);

// Loop through list to locate the target organization.
OrganizationDetail orgInfo = null;
foreach (OrganizationDetail orgDetail in orgResponse.OrganizationDetails)
{
    if (orgDetail.OrganizationName.Equals("AdventureWorksCycle"))
    {
        orgInfo = orgDetail;
        break;
    }
}

// Check whether a matching organization was not found.
if (orgInfo == null)
    throw new Exception("The specified organization was not found.");

After you obtain the organization details, you can then access the CrmService and MetadataService Web services to perform your business logic using the following code:

CrmAuthenticationToken token = new CrmAuthenticationToken();
token.AuthenticationType = 0;    //AD authentication type
token.OrganizationName = orgInfo.OrganizationName;

CrmService crmService = new CrmService();
crmService.Url = orgInfo.CrmServiceUrl;
crmService.CrmAuthenticationTokenValue = token;
crmService.Credentials = System.Net.CredentialCache.DefaultCredentials;
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset