Jer
Jer

Reputation: 383

CRM 365 returns CommunicationException on every call

I have a service that calls CRM 365. The authentication is done with OAuth resp. a bearer token. This worked like a charm but suddenly a CommunicationException is thrown on every call. Maybe this is due to the update of the CRM version to v9.

This is how I create my IOrganizationService:

var crmProxy = new OrganizationWebProxyClient(serviceUri, false)
                   {
                       HeaderToken = bearerToken
                   };

where serviceUri is something like https://mydomain.crm.dynamics.com/xrmservices/2011/organization.svc/web?SdkClientVersion=9.0.0.0

When I make a call against this proxy (like ExecuteRequest or RetrieveMultiple) a CommunicationException is thrown with the following message:

System.ServiceModel.CommunicationException: An error occurred while making the HTTP request to https://mydomain.crm.dynamics.com/xrmservices/2011/organization.svc/web?SdkClientVersion=9.0.0.0. This could be due to the fact that the server certificate is not configured properly with HTTP.SYS in the HTTPS case. This could also be caused by a mismatch of the security binding between the client and the server. ---> System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host

I already updated the CRM SDK assembly to version 9.0.2.4. Still not working.

What can I do?

Upvotes: 1

Views: 501

Answers (1)

Jer
Jer

Reputation: 383

I found the solution.

Dynamics 365 v9.0 enforces TLS 1.2. To enforce TLS 1.2 in the application you have to call the following before making requests:

System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

Alternatively you can switch to .Net 4.6 or above. In these versions TLS 1.2 is the default.

Upvotes: 1

Related Questions