Partilhar via


Transaction Convoy Scope

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

This sample demonstrates how to create a Parallel Convoy messaging activity pattern in conjunction with a TransactedReceiveScope to model a protocol where a number of operations can happen in any order all under the same transaction. This sample also demonstrates how a TransactedReceiveScope automatically creates a new transaction when one is not flowed to the server, so the client does not make use of any transactions.

The sample consists of two workflow projects that represent the client and server. The client project runs a workflow that begins by sending a message to bootstrap the server workflow, which initializes a correlation and starts a transactional scope for the remainder of the messaging activities. The client Sequence activity contains an initial Send and ReceiveReply pair and then a Parallel activity with three branches. Each branch sends a one-way message to the server. The CompletionCondition property of the Parallel activity is set to false so that all three branches complete.

The server workflow is similar to the client workflow except the messaging activities are oriented towards the server side of the communication and they are contained within a TransactedReceiveScope activity so that all work done executes under the same transaction. When the first message is received on the server, a transaction is created and is made ambient for the scope of the TransactedReceiveScope body so that any activity within this scope can access the transaction. After this, all receives execute in parallel. All receives must execute exactly once as described by the completion condition on the parallel activity. An implicit persistence point exists at the end of the TransactedReceiveScope body and the persistence operation is also executed under the same transaction.

To use this sample

  1. Using Visual Studio 2010, open the ParallelConvoySample.sln solution file.

  2. To build the solution, press CTRL+SHIFT+B.

  3. Ensure both projects are set to start.

    1. In Solution Explorer, right-click the solution and select Set Startup Projects.

    2. Select Multiple Startup Projects and ensure the action for both projects is set to Start.

  4. To run the solution, press CTRL+F5.

    The server prints Server is running, which indicates the server is ready.

    Press any key in the client console window to start the sample.

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

<InstallDrive>:\WF_WCF_Samples

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.

<InstallDrive>:\WF_WCF_Samples\WF\Scenario\Transactions\TransactedConvoyScope