Monday 17 June 2013

Dynamics CRM 2011 - "An error occurred when verifying security for the message"

If you attempt to connect to the Dynamics CRM 2011 Web Services using SOAP you may come across this message "An error occurred when verifying security for the message".

In most cases this will be an issue of the server and client times not being close enough so they web server rejects the request.

However I was receiving this message for a completely different reason.

I was using the "CRMOnlineSOAPRequests" example written in C# as a base reference point however I wanted to write my code in PHP so I googled and found a couple of good examples.

Both the C# code and my PHP code returned the required tokens when authenticating however the second token was always 6764 characters in length while the PHP second token was 6796 in length.

I then discovered that I was attempting to connect to the wrong region for my authentication!

If you are receiving this error then ensure that you have selected the correct URN for your region.

  • crmna:dynamics.com - North America
  • crmemea:dynamics.com - Europe, the Middle East and Africa
  • crmapac:dynamics.com - Asia Pacific

6 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Thanks a lot for this, I was searching for this issue solution form last 2 days.

    ReplyDelete
  3. I am trying to create account entity on dynamics crm side, through java code.
    I am getting error "An error occurred when verifying security for the message.". So, after googling the issue I found that the client and server time should be in sync. My timezone is "IST", so I guess the urn I should be using is "crmapac:dynamics.com" (correct me if I am wrong). The wsdl provides "crmna:dynamics.com", so I changed it to the "crmapac". I also made changes in the stubs generated through the wsdl.
    Still this error persists. Also, this error is not consistent. Sometimes I do get '401 Unauthorized'.
    I need to do this urgently.
    Kindly, help me with this.

    ReplyDelete
    Replies
    1. Apologies for the long delay.

      If the wsdl says crmna then you should be using that.

      I would try to do a basic "WhoAmI" call to confirm its not an issue with your request.

      The timezone should be ok as long as the time is set correctly. The larger issue would be if the time on your machine is incorrect. Ensure its exactly right.

      Delete
    2. While analyzing the issue I found that the Application server time was automatically set to 5 min ahead of the time zone,

      so the CRM Server first checks from which time zone the request is coming and then it compares the time of the request with the actual time of that time zone. If it finds the request time is ahead of actual time of that time zone,then it sends the error.

      Delete
  4. Thanks a lot - I had just cloned my disk to move to another machine and couldn't work out why I could not connect to Dynamics anymore. I just toggled "Set time automatically flag" and toggled the "Set time zone automatically" located in windows Date and Time settings.

    ReplyDelete