Loading...

Can’t Connect When Clock Wrong

View: 707    Dowload: 0   Comment: 0   Post by: admin   Category: Embedded Systems   Fields: Other

Probably, the title of this post summaries it well, but there is some detail worth explanation. I was developing an Azure Function app which was basically integrating data between CRM and another system. The major functionality of this application was complete and tested. Two weeks ago, when I came back from leave, I found my application which was working fine before could not connect to CRM. I was using Microsoft.Xrm.Tooling assembly with the following code, but now it started returning null:

public static IOrganizationService GetOrganizationService(ref TraceWriter log)
{
    IOrganizationService _orgService = null;
    string connectionstring = ConfigurationManager.AppSettings["connectionstring"].ToString();
    CrmServiceClient conn = new Microsoft.Xrm.Tooling.Connector.CrmServiceClient(connectionstring);
    _orgService = (IOrganizationService)conn.OrganizationWebProxyClient != null
                ? (IOrganizationService)conn.OrganizationWebProxyClient
                : (IOrganizationService)conn.OrganizationServiceProxy;

    return _orgService;
}

CrmServiceClient has two very useful properties LastCRMError and LastCRMException which were showing this error message:

Unable to Login to Dynamics CRMOrganizationWebProxyClient is nullOrganizationServiceProxy is null

Tried looking for solutions and found the following suggestions:

  1. In connection string, try Organization unique name instead of friendly name
  2. May be assembly version is not compatible or code/ connection string should be written differently
  3. Use ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; before connection

but none of these worked in my case. I contacted Microsoft support and they confirmed there was no such update or roll out that might have caused this but the good thing is they were still willing to help. 

I tried different types of applications, environments and versions, but no luck.

At last, while testing the following code, the error was a little more meaningful:

IServiceManagement orgServiceManagement 
   = ServiceConfigurationFactory.CreateManagement
     (new Uri("https://myCrmInstance.crm5.dynamics.com/XRMServices/2011/Organization.svc"));

AuthenticationCredentials authCredentials = new AuthenticationCredentials();
authCredentials.ClientCredentials.UserName.UserName = "user@email.com";
authCredentials.ClientCredentials.UserName.Password = "*********";
AuthenticationCredentials tokenCredentials = orgServiceManagement.Authenticate(authCredentials); 
OrganizationServiceProxy organizationProxy = new OrganizationServiceProxy(orgServiceManagement,
                                             tokenCredentials.SecurityTokenResponse);

Entity contact = new Entity("contact");
contact.Attributes["firstname"] = "Yawer";
contact.Attributes["lastname"] = "Iqbal";

var contactId = organizationProxy.Create(contact)

“The security timestamp is invalid because its creation time (‘2018-04-01T12:30:45.790Z’) is in the future. Current time is ‘2018-04-01T12:24:29.185Z’ and allowed clock skew is 00:05:00′.”

Getting hint about time, I found time on my machine is 6 minutes behind. What caused this time change, I still don’t know but since it was the difference of just 6 minutes, I couldn’t notice this change. I corrected the time and everything started working as it was. I thought of doing a little experiment and moved the clock 6 minutes ahead of the current time and as per expectation, the error was different:

An unsecured or incorrectly secured fault was received from the other party. See the inner FaultException for the fault code and detail.

and inner exception:

An error occurred when verifying security for the message.

Hope this sharing will save someone’s time.

Can’t Connect When Clock Wrong

Probably, the title of this post summaries it well, but there is some detail worth explanation. I was developing an Azure Function app which was basically integrating data between CRM and another system.

Posted on 30-05-2018 

Comment:

To comment you must be logged in members.

Files with category

  • Can’t Connect When Clock Wrong

    Can’t Connect When Clock Wrong

    View: 707    Download: 0   Comment: 0

    Category: Embedded Systems     Fields: Other

    Probably, the title of this post summaries it well, but there is some detail worth explanation. I was developing an Azure Function app which was basically integrating data between CRM and another system.

  • OpenTheme : An open source graphic user interface (GUI) toolkit

    OpenTheme : An open source graphic user interface (GUI) toolkit

    View: 4677    Download: 4   Comment: 0

    Category: Embedded Systems     Fields: Other

    OpenTheme is an XML based GUI toolkit with a set of foundation class and WYSIWYG editor. Although it's originally designed for full screen GUI, it is also good for Windowed user interface, with full localization support and arbitary...

  • Design State Machine Engine for embedded system development

    Design State Machine Engine for embedded system development

    View: 4297    Download: 4   Comment: 0

    Category: Embedded Systems     Fields: none

    Embedded systems are some special purpose computers that are used inside of devices. Embedded systems generally use micro controllers that contain many functions of a computer on a single device. Embedded systems have to tightly work together with...

  • The StateWizard VC++ Add-in and Engine with Source Code

    The StateWizard VC++ Add-in and Engine with Source Code

    View: 4354    Download: 0   Comment: 0

    Category: Embedded Systems     Fields: none

    In an environment where software systems are more and more complex, concurrent, and real-time oriented, the choice of modeling languages and tools becomes the success key for many projects. This article introduces a cross-platform state-oriented...

  • Template merging with NVelocity and ASP.NET

    Template merging with NVelocity and ASP.NET

    View: 3238    Download: 0   Comment: 0

    Category: Embedded Systems     Fields: Other

    If you have ever tried to implement a newsletter system or a service for communicating with website users, you have probably faced the requisite to send multiple email messages with a common template and some differences, like a personalized greeting...

  • Use PowerShell to Manage your Intel AMT Data

    Use PowerShell to Manage your Intel AMT Data

    View: 2166    Download: 0   Comment: 0

    Category: Embedded Systems     Fields: Other

    This article is in the Product Showcase section for our sponsors at CodeProject. These reviews are intended to provide you with information on products and services that we consider useful and of value to developers.

  • A C++ Embedded Web Server

    A C++ Embedded Web Server

    View: 3359    Download: 1   Comment: 0

    Category: Embedded Systems     Fields: Other

    Do you have a web page or two? Nothing fancy, perhaps, but a neat demonstration of what can be achieved with a handful of HTML tags? Do you have a sophisticated C++ Windows desktop application which now needs to be controlled and monitored remotely?...

  • Java/.NET Integration as Simple as Possible

    Java/.NET Integration as Simple as Possible

    View: 1696    Download: 2   Comment: 0

    Category: Embedded Systems     Fields: Other

    For a number of years, I have been developing software for integrating applications written in different platforms. And in my business, I face with interoperability issues: Java and C++, Java and COM, Java and .NET. To solve them, I have developed a...

 
File suggestion for you
Loading...
File top downloads
Loading...
Loading...
Codetitle - library source code to share, download the file to the community
Copyright © 2018. All rights reserved. codetitle Develope by Vinagon .Ltd