Hi,
We have recently spun up a trial of Dynamics 365 in the UK region and these are now being deployed to xxx.crm11.dynamics.com (rather than xxx.crm4.dynamics.com which is the EMEA region). However, we have found that connecting to the API on these
environments is a little bit hit and miss. Below is a simple piece of code that connects to the environment and simply retrieves a list of users.
When running this code with a connection string against an environment in the crm4.dynamics.com realm it works 100%. Switching the connection string to use environments in the crm11.dynamics.com realm means the (otherwise) same code is only successful
about 50% of the time. No exceptions are thrown, the organisation service is simply returned as null. We've tried switching the connection string between using the organisation's unique-name and the url-name but the results
are the same. Also tried on two different client machines.
Has anyone seen this before? Any ideas what's going on here? It's got us baffled.
Referenced assemblies are (from D365 SDK):
Microsoft.Crm.Sdk.Proxy v8.2.0.749
Microsoft.Xrm.Sdk.dll v8.2.0.713
Microsoft.Xrm.Sdk.Deployment.dll v8.2.0.749
Microsoft.Xrm.Tooling.Connector.dll v2.2.2.807
Microsoft.IdentityModel.Clients.ActiveDirectory.dll v2.22.30211.1727 Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll v2.22.30211.1727
Code:
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Tooling.Connector;
using System;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
string connectionString = @"AuthType=Office365;Username=<username>; Password=<password>;Url=https://org-unique-name.crm11.dynamics.com";
CrmServiceClient crmServiceClient = new CrmServiceClient(connectionString);
IOrganizationService organisationService = crmServiceClient.OrganizationServiceProxy;
if(organisationService != null)
{
string fetchXml = @"<fetch>
<entity name='systemuser'>
<attribute name='systemuserid' alias='systemuserid' />
<attribute name='fullname' alias='fullname' />
</entity>
</fetch>";
Microsoft.Xrm.Sdk.Query.FetchExpression query = new Microsoft.Xrm.Sdk.Query.FetchExpression(fetchXml);
Microsoft.Xrm.Sdk.Messages.RetrieveMultipleRequest retrieveMultipleRequest = new Microsoft.Xrm.Sdk.Messages.RetrieveMultipleRequest();
retrieveMultipleRequest.Query = query;
Microsoft.Xrm.Sdk.Messages.RetrieveMultipleResponse retrieveMultipleResponse = (Microsoft.Xrm.Sdk.Messages.RetrieveMultipleResponse)organisationService.Execute(retrieveMultipleRequest);
foreach(Microsoft.Xrm.Sdk.Entity xrmEntity in retrieveMultipleResponse.EntityCollection.Entities)
Console.WriteLine(xrmEntity.Id.ToString());
}
else
Console.WriteLine("Organisation service is null - it shouldn't be");
Console.WriteLine();
Console.WriteLine("Done. Press any key to quit");
Console.ReadKey();
}
}
Thanks,
Jon