web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Connection issue with SDK

(0) ShareShare
ReportReport
Posted on by 25

I have seen this issue discussed in many forums, and have seen lots of different answers, but none of those answers seem to reliably fix the issue that I am seeing.

I use the SDK in a .NET application to connect to Dynamics 365, using Microsoft.Xrm.Sdk and related libraries, using Office365 authentication. This is for a console application that gets called on an automated basis via Windows Task Manager. I have used the variations of example code and am able to get my app to successfully connect to Dyn365 on my development computer. Also, when I then copy that app to the production server, it also connects to Dyn365 - most of the time. However, many times and for long periods of time, the connection to Dyn365 is unsuccessful, and then all of a sudden it will work again. During those periods, all other network connectivity is working fine, so it's not an issue with the network.

I have tried two variations of connections:

string connectionString = "Url=mydomain.crm.dynamics.com; AuthType=Office365; Username=me@mydomain.com; Password=pw;";

CrmServiceClient client = new CrmServiceClient(connectionString);

client.RetrieveMultiple(q);

And also this method:

var pwd = ConvertToSecureString("pw");
CrmServiceClient client = new CrmServiceClient("me@mydomain.com", pwd, "NorthAmerica", "org12ab12cd", isOffice365: true, useUniqueInstance: true, useSsl: true);
_service = (IOrganizationService)client.OrganizationServiceProxy;
_service.RetrieveMultiple(q);

Both methods work for me, but then also fail very regularly for me (and then continue to fail for hours at a time). By fail, I mean that the CrmServiceClient or the OrganizationServiceProxy are null, and return the error about not being able to connect. I have also verified that my unique organization ID is the correct one from the Developer Resources in CRM, and also verified that username/password are correct - again this works most of the time, but then just fails for unexplained reasons.

Does anyone have any ideas what might be going on, or how I might be able to better diagnose exactly what is happening?

*This post is locked for comments

I have the same question (0)
  • Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    Can you put some error logging/tracing in your application, and see if there are any errors that come up when you are unable to connect?

  • anthony56 Profile Picture
    25 on at

    When I enable the XRM diagnostics, the logging shows entries like this:

    Microsoft.Xrm.Tooling.Connector.CrmServiceClient Error: 2 : Unable to Login to Dynamics CRM

    Microsoft.Xrm.Tooling.Connector.CrmServiceClient Error: 2 : OrganizationServiceProxy is null

    Microsoft.Xrm.Tooling.Connector.CrmServiceClient Information: 8 : Using User Specified Server

    Microsoft.Xrm.Tooling.Connector.CrmServiceClient Information: 8 : Trying Live Discovery Server, (North America) URI is = disco.crm.dynamics.com/.../Discovery.svc

    Microsoft.Xrm.Tooling.Connector.CrmServiceClient Information: 8 : DiscoverOrganizations - Initializing Discovery Server Object with disco.crm.dynamics.com/.../Discovery.svc

    Microsoft.Xrm.Tooling.Connector.CrmServiceClient Verbose: 16 : DiscoverOrganizations - attempting to connect to CRM server @ disco.crm.dynamics.com/.../Discovery.svc

    Microsoft.Xrm.Tooling.Connector.CrmServiceClient Error: 2 : Source : System.ServiceModel

    Method : Retrieve

    Date : 7/19/2017

    Time : 5:10:30 PM

    Error : Metadata contains a reference that cannot be resolved: 'disco.crm.dynamics.com/.../Discovery.svc;sdkversion=8.2'.

    Stack Trace : at System.ServiceModel.Description.MetadataExchangeClient.MetadataRetriever.Retrieve(TimeoutHelper timeoutHelper)

      at System.ServiceModel.Description.MetadataExchangeClient.ResolveNext(ResolveCallState resolveCallState)

      at System.ServiceModel.Description.MetadataExchangeClient.GetMetadata(MetadataRetriever retriever)

      at System.ServiceModel.Description.MetadataExchangeClient.GetMetadata(Uri address, MetadataExchangeClientMode mode)

      at Microsoft.Xrm.Sdk.Client.ServiceMetadataUtility.RetrieveServiceEndpointMetadata(Type contractType, Uri serviceUri, Boolean checkForSecondary)

      at Microsoft.Xrm.Sdk.Client.ServiceConfiguration`1..ctor(Uri serviceUri, Boolean checkForSecondary)

      at Microsoft.Xrm.Sdk.Client.ServiceConfigurationFactory.CreateManagement[TService](Uri serviceUri, Boolean enableProxyTypes, Assembly assembly)

      at Microsoft.Xrm.Sdk.Client.ServiceConfigurationFactory.CreateManagement[TService](Uri serviceUri)

      at Microsoft.Xrm.Tooling.Connector.CrmWebSvc.CreateAndAuthenticateProxy[T](IServiceManagement`1 servicecfg, Uri ServiceUri, Uri homeRealm, ClientCredentials userCredentials, ClientCredentials deviceCredentials, String LogString)

      at Microsoft.Xrm.Tooling.Connector.CrmWebSvc.DiscoverOrganizations(Uri discoveryServiceUri, Uri homeRealmUri, ClientCredentials clientCredentials, ClientCredentials deviceCredentials)

      at Microsoft.Xrm.Tooling.Connector.CrmWebSvc.QueryLiveDiscoveryServer(Uri discoServer)

      at Microsoft.Xrm.Tooling.Connector.CrmWebSvc.FindCrmOnlineDiscoveryServer(CrmOnlineDiscoveryServers onlineServerList, Boolean useO365Servers)

      at Microsoft.Xrm.Tooling.Connector.CrmWebSvc.InitCRM2011Service()

    ======================================================================================================================

    Inner Exception Level 1 :

    Source : System

    Method : GetResponse

    Date : 7/19/2017

    Time : 5:10:30 PM

    Error : The operation has timed out

    Stack Trace : at System.Net.HttpWebRequest.GetResponse()

      at System.ServiceModel.Description.MetadataExchangeClient.MetadataLocationRetriever.DownloadMetadata(TimeoutHelper timeoutHelper)

      at System.ServiceModel.Description.MetadataExchangeClient.MetadataRetriever.Retrieve(TimeoutHelper timeoutHelper)

    ======================================================================================================================

  • Suggested answer
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    Not sure if this will help, but maybe try this for the connection:

    _service = (IOrganizationService)client.OrganizationWebProxyClient != null ? (IOrganizationService)client.OrganizationWebProxyClient : (IOrganizationService)client.OrganizationServiceProxy;

    I have similar applications connecting to Office 365 with the same code that are working.

    Also, you might want to try and check using the latest version of the SDK assembly files. That can sometimes resolve the issues if not using the latest version.

    You can also check the following post:

    https://community.dynamics.com/crm/b/misscrm360exploration/archive/2017/02/15/error-quot-unable-to-login-to-dynamics-crmorganizationwebproxyclient-is-nullorganizationwebproxyclient-is-nullorganizationserviceproxy-is-nullorganizationserviceproxy-is-null-quot-during-connecting-to-crm-online-using-xrm-too

  • Suggested answer
    tw0sh3ds Profile Picture
    5,600 on at

    Any particular reason why you are doing

    _service = (IOrganizationService)client.OrganizationServiceProxy;

    ?

    CrmServiceClient is already implementing IOrganizationService, just use your "client" variable and you should be ok.

  • anthony56 Profile Picture
    25 on at

    Thank you so much for your reply. I'm not sure what ultimately fixed it, but I 1) made the changes suggested here, 2) updated to CRM SDK 8.2.1.1, and 3) did a fresh rebuild and copied ALL files to the deployment location. Now I no longer get the "Metadata contains a reference that cannot be resolved" error in the XRM log file, and it seems to be working perfectly. Thanks again for your suggestions.

  • anthony56 Profile Picture
    25 on at

    Ok, well, I thought it was working, but alas the same issue has arisen. It ran fine for a few hours, and then all of a sudden stopped working. In the XRM log file, I see this:

    Metadata contains a reference that cannot be resolved: 'disco.crm.dynamics.com/.../Discovery.svc;sdkversion=8.2'

    followed by this:

    Error : The operation has timed out

    Stack Trace : at System.Net.HttpWebRequest.GetResponse()

    Microsoft.Xrm.Tooling.Connector.CrmServiceClient Error: 2 : Unable to Login to Dynamics CRM

    I have read through all the various posts on the "Metadata contains..." error, but no resolution yet.

    The problem continues...

  • David Jennaway Profile Picture
    14,065 on at

    The error 'The operation has timed out' does indicate some connectivity issue, rather than a code issue. There's nothing particularly unusual about the network connectivity to the CRM servers, so there's not much that would cause this to fail, while other network access is OK. However, it's worth checking:

    • Is https access working to other servers ? Also, if possible check the TLS version, as it maybe you have a network component that has TLS versions incompatible with the CRM server
    • Any rogue DNS entries for CRM online - either in a HOSTS file, or internal DNS
  • anthony56 Profile Picture
    25 on at

    Thanks for the reply David. Based on your suggestion, I do see some DNS issues going on, which I'm investigating. It seems that 'disco.crm.dynamics.com' resolves to either 134.170.26.25 or 65.55.132.25 at different times of day (for me), and with the DNS issues on my end, that might be causing the issues. On the other hand, I just added one of those addresses to my HOSTS file, and that still didn't work, so that would suggest that DNS is not the culprit. Still investigating...

    Regarding the TLS suggestion, this is running on a Windows 2008 R2 server - what's the best way to check whether there might be some TLS issue going on? However, since this intermittently works just fine, to me that suggests that TLS is not the issue.

  • JohnLeme Profile Picture
    355 on at

    I had it all working until 365 update yesterday. Still haven't found a solution. See stackoverflow.com/.../7920473

  • Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    Did you update SDK version? Can you check with version 8.2 of SDK? You mention that you just upgraded from 2016.1 to 365 (8.2)...

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans