One of powerful features in upcoming Workflow Services 4.0 is definitely correlation between asynchronous messages. When using workflow services at all, you may notice that typical web service scenario Request-Replay is mostly nit very useful. Because workflows are mostly used to perform long running actions, participants in the distributed workflow will need to communicate asynchronously. Such scenarios are very common in BizTalk solutions.
Imagine we have following workflow:
The SendMessageActivity sends the message M1 and ReceiveMessageActivity receive the message M2 asynchronously. Because multiple workkflow instances can run the same workflow, the underlying execution engine needs to known which message of type M2 belongs to which workflow instance. This process
is known as correlation. Because workflow can correlate messages based on their content (for example one can decide “all message with the same order id belongs to same workflow instance”) this feature is called “Content Based Correlation”.
Before you proceed, be sure that the contract has a property (attribute) with name OrderId.
How to make it working?
Select the top level Sequence or other activity in the workflow. Click the “Variables” button at the bottom left of the designer. Click the “Add variable” button in the “Variables created by me” section. In the “Variable name” column type “OrderCorrelation” (Assuming the correlation will be based on Order Identifier). In the “Type” column expand the drop down and select “Browse for Types…” . Following window appears:
Now, select the SendMessageActivity and set correlation handle as shown below:
First select the proper endpoint “SendMessageEndpoint”. OrderIdQuery is the name of “correlated content” and //temp:OrderId is the XPath to the OrderId XML (message) property. Temp stands for tempuri namespace as shown in the snapshot of the correlation represented in XAML:
Now, do the same for receive message shape:
Note that correlation handle “CorrelationToken”, Name “OrderIdQuery” and XPath “//temp:OrderId” by send and receive activities have to match exactly!
Remark: In some later CTP build of VS2010 this value can be set in XAML only as follows (example of Customer.EmailAddress):
If this is not the case you may get following two errors:
If correlation content query (OrderIdQuery) is not set at all:
System.WorkflowServiceModel 4.0.10924.1: Throwing exception: System.ServiceModel.ProtocolException: A correlation query yielded an empty result set. Please ensure correlation queries for the endpoint are correctly configured.
If correlation content query is set, but with differnet names (e.g. OrderIdQuery vs. OrderIDQuery):
System.WorkflowServiceModel 4.0.10924.1: Throwing exception: System.InvalidOperationException: The CorrelationHandle is already in use with SubInstance 'ae9179ac-e7cd-908b-8a1b-fb0760c7f8a2', so it cannot be used with SubInstance '50ab78c7-e00e-2800-05ba-a81a3d160830'.
Unable to resolve the type '{http://schemas.microsoft.com/netfx/2009/xaml/workflowmodel}Sequence'. Ensure that the type name is correct, the Assembly containing the type is loaded or a valid Xmlns mapping for the assembly is specified to the XamlSchemaTypeResolver.
Posted
Apr 08 2009, 08:40 AM
by
Damir Dobric