Using the CrmDiscoveryService Web Service In CRM4.0: On-Premise

CrmDiscovery service is a global installable level service that allow the caller to determine the correct organization and URL for his/her need.

Below example show how to create and configure CrmDiscoveryService Web Service proxy.

 

// Create and configure the CrmDiscoveryService Web service

proxy.

CrmDiscoveryService discoveryService = new

CrmDiscoveryService();

discoveryService.UseDefaultCredentials = true;

discoveryService.Url

=”http://localhost/MSCRMServices/2007/AD/CrmDiscoveryServic

e.asmx”;

// Retrieve the list of organizations that the logged on

user belongs to.

RetrieveOrganizationsRequest orgRequest = new

RetrieveOrganizationsRequest();

RetrieveOrganizationsResponse orgResponse =

(RetrieveOrganizationsResponse)discoveryService.Execute(org

Request);

// Locate the target organization in the list.

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.”);

 

Author: Arvind Singh

Solution Architect with 15+ years of exp. Dynamics CRM, Power Platform, Azure which includes Solution, Design, Development, Deployment, Maintenance and support experience.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: