Wednesday 21 February 2018

Console Application Service for Latest Versions

Retrieve service using the console in Dynamics 365 V9.0



While Retrieving service we will be getting an error in Dynamics 365 V9.0. To avoid that error, we need to add one additional line to our code for the Retrieve Service.

But What can be the issue?
Microsoft Introduced Transport Security Layer 1.2 (TSL 1.2) for SDK assemblies. So an updated version of CRM we are having TSL 1.2

.net Framework Version 4.6 and above will support TSL by default. While coming to lower FW versions we are getting connection issues.

What can be the solution?

Add the following line of code while retrieving service:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

And followed by the complete code here:
  public static IOrganizationService RetrieveService(Uri organizationURL, string userName, string password)
 {
   var url = organizationURL;
   ClientCredentials cre = new ClientCredentials();
   cre.UserName.UserName = userName;
   cre.UserName.Password = password;
   ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
   using (OrganizationServiceProxy proxy = new OrganizationServiceProxy(url, null, cre, null))
      {
         proxy.EnableProxyTypes();
         IOrganizationService service = (IOrganizationService)proxy;
         return service;
       }
   }

4 comments:

  1. Nice post, I had the issue and struggled a lot for this.. Thanks for the information.

    ReplyDelete
  2. Its working fine.
    Thank you so much for the information

    ReplyDelete
  3. thanks for solution it really helped me.

    ReplyDelete