Before one correlation can be used we first need to define the correlation handle. To do this click on Variables tab (bottom left in WF designer) of the activity which is the parent of receive shape, which will initialize the correlation. Enter the name of variable (in this case “correlator”) and set the type on CorrelationHandle.
Now, click on the receive message shape and in the list of properties should appear following three values:
- Correlates On
- Correlates with
- Correlation Initializes
First of all the correlation handle has to be initialized. This can be done for example at the very first receive message shape. Click CorrelationInitializers and following window will appear:
In this window you will see handle as already initialized. This is automatically done when you drag the Receive/SendResponse shape to designer. Create new correlation initializers (see “correlator”). Select Query Correlation Initializer. Then select the property which should initialize the correlator:
In my case I selected OrderID, which is a property of data contract OrderRequest. That mean we have initialized the correlation handle on property OrderID of the message OrderRequest. Please note that there is a property “CanCreateInstance” of the receive shape, which should be set on TRUE if the receiving message of this shape has to start the new workflow.
Now I select some other receive shape which requires the correlation.
The property CanCreateInstance of this shape has to be set on FALSE, because this shape will not start the new instance of the workflow. Instead, this shape will post the message to already running WF-Instance. This is exactly the crucial point. How the WF-runtime can now to which instance the message will be posted?
The answer is: “content based correlation”. To make this possible set the property CorrelatesWith (of second receive shape) on the name of correlation handle called. In our case is this “correlator”-variable.
Now, select the value of Correlates With as shown at the next picture:
Note that we now correlate property OrderID of message ConfirmationRequest, which is different one than OrderRequest.OrderID. Briefly that mean: “The message of type ConfirmationRequest will be posted to running instance of Workflow which has the same OrderID in as the message OrderRequest which has started the workflow instance.
That’s it :)
Posted
Oct 20 2009, 12:27 PM
by
Damir Dobric