BloggingAbout.NET
Thoughts of developers
Windows Workflow 4.0 Correlation Example Continued…

Using the sequential workflow built in the previous post, we will continue the correlation example using Windows Workflow 4.0.

The following illustrates the current workflow so far:

image

The concept is the workflow instance will now wait until either an OrderApproval for the same order is received or a specified amount of time elapses.  This is done by using a Pick shape with two branches.  In the screenshot below, note the altered display name properties:

 image

To capture the OrderApproval message, drop a ReceiveAndSendReply shape into the Trigger section of the ApprovalReceived shape.  Set the receive shape’s DisplayName and OperationName to ReceiveApproval and SubmitApproval.  Set the DisplayName of the SendReply shape to AcknowledgeApproval:

image

Next specify the approval message to be received.  This will contain two parameters: the orderNumber to be used to correlate and an OrderApproval object.  Note: specify the Assign To value for the approval parameter.

image

The reply will contain a string to acknowledge the approval was received.  This is specified in the SendReply shape’s Content property:

System.String.Format("Order {0} approval was set to {1} on {2}.", order.OrderNumber, order.Approval.WasApproved, order.Approval.DateApproved)

image

In the ApprovalNotReceived branch, drop a Delay shape in the Trigger section and a TerminateWorkflow shape in the Action section:

image

Change the Delay shape’s properties as follows (for this example, 30 seconds will be the duration to wait until an approval is received):

image

The TerminateWorkflow shape will need an Exception specified and a Reason entered:

System.String.Format("Order {0} was not approved within the Timeout period.", order.OrderNumber)

image

Now to correlate the two messages so the OrderApproval is associated with the initial Order.

First define a new CorrelationHandle variable with the scope of the entire Sequential Service:

image

In the ReceiveNewOrder shape, set the CorrelatesWith property to the corr variable:

image

Initialize the CorrelationHandle by adding the variable in the CorrelationInitializers property:

image

In the XPath Queries section specify to use the value of the Order.OrderNumber received in the message:

image

To associate the OrderApproval message, set the ReceiveApproval’s CorrelatesWith property to use the corr variable:

image

Instead of initializing a new CorrelationHandle, we are going to use the existing handle so set the CorrelatesOn property (note the Query specifies the orderNumber parameter):

image

That’s it.  So run the project to verify the correlation works.

Notice the project now has two endpoints: one for submitting the initial order and one for submitting the approval:

image

Invoke a 101 order and verify the result:

image

Within 30 seconds submit an approval for order 101 (in my example, I did not approve the order):

image

To test the timeout, submit another order and wait 30 seconds.  Now check the Tracked Events in the AppFabric dashboard (it might take a little while before the event is added to monitoring):

image

In the screenshot above, note the Reason is specified in the Errors tab.


Posted Fri, Jan 14 2011 8:24 AM by chilberto
Filed under: , ,

Comments

csdj wrote re: Windows Workflow 4.0 Correlation Example Continued…
on Wed, Aug 24 2011 4:03 PM

Please the source!

Dhara Patel wrote re: Windows Workflow 4.0 Correlation Example Continued…
on Sat, Mar 17 2012 1:15 PM

Add a Comment

(required)  
(optional)
(required)  
Remember Me?

Please add 1 and 3 and type the answer here:
Copyright © 2003-2010 BloggingAbout.NET