This topic applies to Windows Workflow Foundation 4 (WF4).

This sample demonstrates how the messaging activities can be used with context-based correlation to correlate without having to explicitly specify correlation handles or queries.

Sample Details

This sample uses the .NET Context Exchange protocol that was introduced in .NET Framework version 3.5. The protocol outlines the message exchange pattern that is used to ensure that a client application communicates with the proper instance of the service by using a well-known message header (the Context header). In .NET Framework version 4, this mechanism is just one particular type of correlation: a context-based correlation.

The ContextService returns the message header on the reply message of the first operation invocation (OpenBankAccount) and the client is responsible for re-attaching that header on its subsequent calls (Deposit and Withdraw). The ContextClient accomplishes this by using a CorrelationScope activity. Because the ContextService is hosted in WorkflowServiceHost, an implicit CorrelationScope is created for that workflow that allows the context-based correlation to work automatically.

To use this sample

  1. Open the NetContextExchangeCorrelation.sln solution in Visual Studio 2010.

  2. Press CTRL+SHIFT+B to build the solution.

  3. Set multiple start up projects by right-clicking the Solution and selecting Set Startup Projects. Add ContextService and ContextClient (in that order) as multiple start up projects.

  4. Press CTRL+F5 to run the application. The ContextClient console shows the calls being made to the service. The ContextService console shows these calls being received and processed.

Ee662963.Important(en-us,VS.100).gif Note:
The samples may already be installed on your machine. Check for the following (default) directory before continuing.


If this directory does not exist, go to Windows Communication Foundation (WCF) and Windows Workflow Foundation (WF) Samples for .NET Framework 4 to download all Windows Communication Foundation (WCF) and WF samples. This sample is located in the following directory.