Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

An error occurred when verifying security for the message on CRM SDK

I got an error when connecting the CRM 2013 from CRM SDK code. The error message is

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

And here is the inner exception message:

An error occurred when verifying security for the message.

The CRM is installed on Virtual Box that consist of:

  • Windows Server 2012
  • CRM 2013
  • SQL Server 2012
  • Timezone and datetime between Host and guest machine already the same

I have test the CRM connection with below scenario

  • Able to access CRM from host browser (Windows 7)
  • Able to run following code (CRM SDK) from guest machine (Win Server 2012)
  • Not able to run following code from host machine (Windows 7)

Here is my source code:

        var uri = new Uri(@"http://XXXX/MRC/XRMServices/2011/Organization.svc");
        var username = @"XX\Administrator";
        var password = "password";

        _credential.UserName.UserName = username;
        _credential.UserName.Password = password;

        using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(uri, null, _credential, null))
        {
            serviceProxy.EnableProxyTypes();
            IOrganizationService service = (IOrganizationService)serviceProxy;
            MRServiceContext context = new MRServiceContext(service);
            var query = context.ContactSet.ToList();
            foreach (var item in query)
            {
                Console.WriteLine(item.FirstName);
            }
        }

Thanks in advance.

like image 624
Hendra Avatar asked Dec 12 '22 06:12

Hendra


1 Answers

Oppss this is a stupid mistake that I have ever made. This issue is caused by the guest machine date is in the past compare with the host machine. I only checked the time on guest and host machine that already the same. But, I forgot to check the date.

Here is the clue:

System.ServiceModel.Security.MessageSecurityException, System.ServiceModel,             
Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType>
<Message>The security timestamp is stale because its expiration time 
('2014-04-03T06:49:23.526Z') is in the past. Current time is '2014-04-04T06:44:14.447Z' 
and allowed clock skew is '00:05:00'.</Message><StackTrace>   at 
System.ServiceModel.Security.SecurityTimestamp.ValidateFreshness(TimeSpan timeToLive, 
TimeSpan allowedClockSkew)

Here is the best way to check some error that occurred on CRM (doesn't appear on client side):

  1. Enable tracing in Microsoft Dynamics CRM to get the real issue that occurs
  2. Read the log/stack trace file that usually available on C:\Program Files\Microsoft Dynamics CRM\Trace

Hope this steps is useful for the others.

like image 158
Hendra Avatar answered Dec 13 '22 19:12

Hendra