Update 18-Nov-2016: Bugs reported have been fixed and there are no compelling reasons (beyond the support of the existing codebase) to continue use of Microsoft.Xrm.Client.
One thing you’d notice about Dynamics CRM 2016 SDK is that some of the assemblies has gone MIA. For example, Microsoft.Xrm.Client, a home to some useful developers extensions, including a mighty CrmConnection class, is nowhere to be found. These extensions were taken over by Xrm Tooling family, the one we mentioned before.
CrmServiceClient, in particular, looks like a solid replacement for CrmConnection but, as with any new libraries, there are few gotchas.
This is the only connection string that worked for us so far in non-interactive mode:
CrmServiceClient conn = new CrmServiceClient( "ServiceUri=https://orgname.contoso.com/orgname;" + "AuthType=IFD;Domain=anything;" + "UserNameemail@example.com;Password=pass@word1;" + "LoginPrompt=Never;");
Note the following:
- Url must be in the form of https://orgname.contoso.com/orgname. For on-premises and IFD deployments the connector expects orgname to be at the end and looks like it does not make any attempt to deduce orgname from the server url.
- Domain name must be specified but it’s not passed via claims, so it can be anything. Really any non-empty string o__O
- Username must be UPN. If it’s not, then, since domain name is not passed it, ADFS 3.0 throws a fit (ADFS 2.0 assumes the domain)
The following syntax works as well:
CrmServiceClient conn = new CrmServiceClient( new System.Net.NetworkCredential( "firstname.lastname@example.org", "pass@word1"), AuthenticationType.IFD, "orgname.contoso.com", "443", "orgname", useSsl: true);
Same restrictions apply except that there is no need to specify the dummy domain name.
Whilst we manage to get CrmServiceClient working for non-interactive IFD connections, we’re heard from reliable sources that it does not work currently in Azure Web Apps / App Service Web Apps while attempting to connect to CRM Online.
The workaround? You can still use the bits from CRM 2015 SDK and its very reliable CrmConnection class – just make sure to load the other Nuget packages for CRM 2016 first and then add Microsoft.Xrm.Client.