What is the issue?
While coding with C#, developers struggles to connect with Dynamics 365. OrganizationService/ OrganizationServiceProxy object contains null and connection fails.
The reason behind this issue –
1. dll support
2. Wrong Connection String
3. Configuration settings
4. SSL/TLS setting
solution according to the reason-
1. dll Support-
You should know which dlls are supported to connect Dynamics 365.
Many times the CRM versions differs and due to CRM upgrades the dlls used becomes outdated for new Versions. Currently many developers faces this issue if you are using Dynamics365 online version . Current version of CrmSDK is V18.104.22.168. and this should be used.
You can add reference of CrmSDK by using Nuget Package Manager-
You can change the version according to recent updates by Microsoft.
2. Connection String-
Wrong connection string might be the problem and for Dynamics 365 online version you can use connection string like-
<YourOrgName>– This is your Organization Name.
<CRMRegion>– This is the Region you choose while creating organization.
Also you can find this string navigating Customization-> Developer Resources in Dynamics 365.
Other way to connect CRM is providing each parameter Separately like-
Microsoft.Xrm.Tooling.Connector.CrmServiceClient conn = new CrmServiceClient(uName, pwd, "NorthAmerica", _crmOrganizationName, isOffice365: true);
Also you need to provide Username and password(converted to secured password) Properly.
Many times application throws an exception like “Metadata contains a reference that cannot be resolved” .
You provides the connection string properly, every thing is correct but still you found the OrganizationService/ OrganizationServiceProxy showing null.
This happens in some particular domain networks. In this case you have to enable the Proxy setting and for this add the following tag under the configuration tag to your Web.Config /app.config file-
<defaultProxy useDefaultCredentials=”true” enabled=”true”>
This will only use the credentials provided by you in connection string.
4. SSL/TSL settings-
Your application fails to connect Dynamics365 CRM if it is using some particular security protocol. To connect successfully , you need to explicitly mention the security by adding the following line just before the connection establishment lines-
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
Use Tls12/SSL/Tls11 according to security protocol used by Dynamics365 .
Hope this will be helpful to connect your organization.