0
votes

I need to modify my existing code to connect to Microsoft Dynamics 365 instead of an on-premises installation. I'm currently using the Microsoft.Xrm.Tooling.Connector and we want to keep this so that the impact on the code is as low as possible.

So I have updated my connection string to use following format: AuthType=ClientSecret;url=https://xxx.dynamics.com;ClientId=xxx;ClientSecret=xxx;

I have updated the nuget package Microsoft.CrmSdk.XrmTooling.CoreAssembly to the latest version 9.1.0.64. The other related packages were updated at the same time.

The code I use is:

var client = new CrmServiceClient(connstring);

Unfortunately this is not working in my .net 4.7.1 web.app I get following errors:

CurrentAccessToken = 'CurrentAccessToken' threw an exception of type 'System.NullReferenceException'

LastCrmError = "One or more errors occurred. => An error occurred while sending the request. => Unable to connect to the remote server => A connection attempt failed because the connected party did not properly respond after a period of time, or established connection fai..."

I have also already tried to add following line but the error stays:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

To be sure that it's not related to my existing web app I have started a new project and I have included a new web app (mvc) and a new console app. Even in that new project the web app is not working but the console app is working.

A difference I see is that for CrmConnectOrgUriActual the console app contains XRMServices/2011/Organization.svc/web?SDKClientVersion=9.0.45.2156 but in the webapp this is only XRMServices/2011/Organization.svc/

Is there maybe something extra that need to be configured in the web app? Can someone help me with this?

Update

I was able to see more of the error message and it was mentioning also following message: AuthorityUnable to connect to CRM: Need a non-empty authority

1

1 Answers

0
votes

I did a new search on "Need a non-empty authority" based on the full error details. One of the results was the following article: https://www.kashanahmed.com/2020/06/we-were-trying-to-connect-dynamics-365.html

So it seems that my issue was caused by the proxy server of our company.

Adding following lines in the web.config solved my issue

  <system.net>
    <defaultProxy useDefaultCredentials="true" enabled="true">
      <proxy usesystemdefault="True" proxyaddress="http://theproxy" />
    </defaultProxy>
  </system.net>