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:

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:

When the settings are saved, create the virtual directory:

I renamed the file to be ApprovalService

and updated the WorkflowService properties ConfigurationName and Name to ApprovalService.

In this example, I will use two datacontracts: Order and OrderApproval. The process flow will be as follows:
- Order submitted for approval
- 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:

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:

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:

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

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

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

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

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

Set the payload of the SubmitOrder method and click Invoke

The Response should be displayed:

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

Notice how the Workflow Service properties influence the tracked events.
Continued…
Posted
Thu, Jan 13 2011 2:12 PM
by
chilberto