Posted by: Arvind Singh | January 20, 2009
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.”);