BloggingAbout.NET
Thoughts of developers
Windows Workflow 4.0 Correlation Example

The following is an example of performing correlation using Windows Workflow 4.0.

First create a new project based on the WCF Workflow Service Application template:

image

Because I am interested in tracking the events in AppFabric during development, I will change the projects Web properties to host the service IIS instead of the Visual Studio Development Server:

image

When the settings are saved, create the virtual directory:

image

I renamed the file to be ApprovalService

image

and updated the WorkflowService properties ConfigurationName and Name to ApprovalService. 

image

In this example, I will use two datacontracts: Order and OrderApproval.  The process flow will be as follows:

  1. Order submitted for approval
  2. Workflow waits until either a subsequent OrderApproval is received or the service times out

A new folder named Contracts is created to organise the new contracts:

image

Add two classes: Order and OrderApproval

Note: if your template does not have a reference to System.Runtime.Serialization, then add reference.  You will be able to tell if the DataContract attribute does not resolve with the System.Runtime.Serialization:

image

The Order contract

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Runtime.Serialization;
 
namespace Spike.OrderApproval.Contracts
{
    [DataContract]
    public class OrderApproval
    {
        [DataMember]
        public bool WasApproved { get; set; }
        [DataMember]
        public DateTime DateApproved { get; set; }
    }
}

The OrderApproval contract

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Runtime.Serialization;
 
namespace Spike.OrderApproval.Contracts
{
    [DataContract]
    public class Order
    {
        [DataMember]
        public int OrderNumber { get; set; }
        [DataMember]
        public OrderApproval Approval { get; set; }
    }
}

In the workflow service, add the following variable to represent a received order:

image

On the receive shape, update the DisplayName, OperationName and ServiceContractName as shown below:

image

Set the content of the receive shape to set the order variable to the received payload:

image

Set the content of the SendReply shape to return a string response:

image

To test the service so far, set the ApprovalService.xamlx as the Start Page

image

Run the project by pressing F5, the WCF Test Client should start:

image

Set the payload of the SubmitOrder method and click Invoke

image

The Response should be displayed:

image

Inside of the AppFabric Dashboard, the following events have been tracked:

image

Notice how the Workflow Service properties influence the tracked events.

Continued…


Posted Thu, Jan 13 2011 2:12 PM by chilberto
Filed under: , ,

Comments

Dhara Patel wrote re: Windows Workflow 4.0 Correlation Example
on Sat, Mar 17 2012 10:51 AM

hi...

at the below step :

Set the content of the SendReply shape to return a string response:

taking order number properties but we are using class order's variable in  the workflow then how will we find orderNumber property from order class because its defined in the OrderApproval Class..

How is that possible ?

Add a Comment

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

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