Content based correlation in Workflow Services 4.0

Damir Dobric Posts

Next talks:

 

    

Follow me on Twitter: #ddobric



 

 

Archives

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:

image

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.

image

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:

image

Now, select the SendMessageActivity and set correlation handle as shown below:

image

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:

image

Now, do the same for receive message shape:

image

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):

image


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

Comments

Damir Dobric Posts wrote Declarative Workflow Services 4.0: Error - InstanceKeyNotFoundException
on 04-10-2009 12:56

Problem Description When working with declarative workflow services, you may get following error: System

DamirDobric wrote Declarative Workflow Services 4.0: Error - InstanceKeyNotFoundException
on 04-10-2009 13:54

Problem Description When working with declarative workflow services, you may get following error: System

Damir Dobric Posts wrote Declarative Workflow Services 4.0: Error - InstanceKeyNotFoundException
on 04-10-2009 18:11

Problem Description When working with declarative workflow services, you may get following error: System

Sumit : Hosting WorkFlow in IIS correlation problem wrote re: Content based correlation in Workflow Services 4.0
on 08-27-2009 12:42

We are have an issue regarding correlation in WorkFlows hosting in IIS. We are using a Declarative Flowchart workflow using the address below which has been added into your web client project via a Service Reference. vmwinxp/.../Service2.xamlx

The weird thing is that if we host the workflow using command prompt like the code below is works fine.

Is there a special way you have to host it in IIS except from point a virtual directory at the folder with the XAMLX file in?

Any help would be much apprepciated!!!

static void Main(string[] args)

       {

           string baseAddress = "localhost/CarRentalService";

           using (WorkflowServiceHost host = new WorkflowServiceHost(typeof(RentCar), new Uri(baseAddress)))

           {

               host.Description.Behaviors.Add(new ServiceMetadataBehavior() { HttpGetEnabled = true });

               host.AddDefaultEndpoints();

               host.Open();

               Console.WriteLine("Car rental service listening at: " + baseAddress);

               Console.WriteLine("Press ENTER to exit");

               Console.ReadLine();

               host.Close();

           }

       }

Alen Siljak wrote re: Content based correlation in Workflow Services 4.0
on 05-12-2010 6:16

Samo da te pozdravim, stari, i da se tu-spasim. Evo, godinu dana nakon originalnog posta, napokon doslo vrijeme da citam ove stvari. :)

Srdacan pozdrav iz Australije

Damir Dobric wrote re: Content based correlation in Workflow Services 4.0
on 05-12-2010 9:32

you are welcome :)

AppFabric CAT | Coordinating "Embarrassingly Parallel” .NET4 Workflow Processes wrote AppFabric CAT | Coordinating "Embarrassingly Parallel” .NET4 Workflow Processes
on 05-24-2011 2:04

Pingback from  AppFabric CAT | Coordinating "Embarrassingly Parallel” .NET4 Workflow Processes

AppFabric CAT | Coordinating “Embarrassingly Parallel??? .NET4 Workflow Processes wrote AppFabric CAT | Coordinating “Embarrassingly Parallel??? .NET4 Workflow Processes
on 05-24-2011 21:27

Pingback from  AppFabric CAT | Coordinating “Embarrassingly Parallel??? .NET4 Workflow Processes

developers.de is a .Net Community Blog powered by daenet GmbH.