Microsoft KB Archive/878435

= You receive an &quot;Error in action posturl&quot; message when a Workflow Rule is run while going back Online in the Microsoft CRM Sales for Outlook Client =

Article ID: 878435

Article Last Modified on 5/22/2007

-

APPLIES TO


 * Microsoft CRM 1.2
 * Microsoft Business Solutions CRM 1.0

-



SYMPTOMS

A workflow rule has been created and implemented in Workflow Manager to respond to the create event of the Opportunity object in Microsoft CRM. When an Opportunity is created, the Post Url action is used to send the opportunityid, createdby, and owningbusinessunit to a custom WebService. The WebService has a function that uses the CRMQuery.ExecuteQuery method to retrieve the value of a custom field used to track a custom quote number, CFSQuoteNum. The highest CFSQuoteNum is determined and incremented by 1. Then the CRMOpportunity.Update method is used to update the current Opportunity with the appropriate custom quote number.

The workflow rule works fine when implemented via the Microsoft CRM Web Client and while online with the Microsoft CRM Sales for Outlook client. However, if multiple opportunities are created while offline in the Microsoft CRM Sales for Outlook Client, the following error is returned in the Workflow Monitor for some, not all, of the Opportunities that were created offline:

Error in action posturl. Failed to connect the url http://localhost/WebService1.asmx/Service1.asmx/UpdateQuoteNum? c:\crm\seteam\src\platform\workflow\service\processengine.inl 5228

CAUSE

Multiple threads produced by the opportunities created offline are causing synchronization issues. One thread is interrupting what another thread is doing, thus leaving the object in an invalid state. Specifically, accessing the same database table at the same time to retrieve the CFSQuoteNum causes the CRMQuery.ExecuteQuery to throw an exception resulting in the error described in the Symptoms section

RESOLUTION

This problem can be solved through correct synchronization of the multiple threads. The multiple instances of the web service need to be synchronized using the .Net framework. A Mutex can be used to synchronize access to an object or to build a low level synchronization mechanism. Using a Mutex we have a way to anchor all synchronization around a single named mutex, which will be shared across all objects, threads and even processes.

To utilized a Mutex in this scenario:

1. Include System.Threading

using System.Threading;

2. Create a new named mutex.

private static Mutex mutex = new Mutex(false,&quot;Service1.asmx.Mutex&quot;);

3. In the beginning of the function that retrieves the CRM data using the CRMQuery.ExecuteQuery and updates the Opportunity using the CRMOpportunity.Update method, wait for the mutex.

mutex.WaitOne;

4. In the end of the function, release the mutex.

finally

{

mutex.ReleaseMutex;

}

REFERENCES

For additional information on the use of Mutexes:

For additional information on Threading:

For additional information on the CRMQuery.ExecuteQuery Method:

Version 1.0:

Version 1.2:

For additional information on the CRMOpportunity.Update Method:

Version 1.0:

Version 1.2:

This article was TechKnowledge Document ID: 35454

Keywords: kbmbsworkflow kbmbsmigrate KB878435

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.