The Microsoft Dynamics CRM 2011 Discovery Service is a web service which lets us determine the organizations that a particular user belongs to. It provides information such as the organisation friendly name, URL endpoints, unique id, version, unique name, URL name, and the current state (whether it is enabled or disabled). In this post, we will take a look at the Discovery Service using a sample application.
The customizations area displays the URLs for each of the available CRM 2011 services under the Developer Resources link.
We will use the URL highlighted in red along with the following code to display the name of the organisations belonging to our CRM deployment.
Uri discoUri = new Uri("http://mycrmserver/XrmServices/2011/Discovery.svc");
NetworkCredential nc = new NetworkCredential
Domain = "mycrmserver",
UserName = "roshan",
Password = "password"
ClientCredentials cc = new ClientCredentials();
cc.Windows.ClientCredential = nc;
DiscoveryServiceProxy proxy = new DiscoveryServiceProxy(discoUri, null, cc, null);
RetrieveOrganizationsRequest request = new RetrieveOrganizationsRequest();
RetrieveOrganizationsResponse response = (RetrieveOrganizationsResponse)proxy.Execute(request);
foreach (OrganizationDetail d in response.Details)
Executing the code above gives the following result:
It is important to note that the Discovery Service will only provide information about the organisations the current user has access to. In our code snippet above, I logged in as “roshan” which returned a list of the five organisations I have access to. If I changed the credentials so that we logged in as user “testuser1”, we would get the following result:
This user only has access to three of the organisations in our CRM deployment; therefore the call to the Discovery Service under this user’s login will only return three organisations.