Use of TransactedReceiveScope

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

This sample shows how to flow a transaction from a client to a server using TransactionScope to create a new transaction on the client and a TransactedReceiveScope to receive a message with a flowed transaction and scope the lifetime of the transaction on the server. The sample consists of two projects that fill the roles of client and server.

Client Application

The client application runs a workflow that prints the distributed transaction ID, sends a message to the server, flows the transaction, receives the reply, prints the distributed transaction ID again and completes. When the distributed transaction ID is initially prints, it is an empty GUID as the transaction is still only local.

Server Application

The server project is similar, however, the workflow is hosted in WorkflowServiceHost because it must listen on an endpoint for the message from the client. The workflow is centered on the TransactedReceiveScope, which receives the flowed transaction from the client, prints the message that was sent, prints the distributed transaction ID and sends the reply to the client. The distributed transaction ID is now a non-empty GUID and if a transaction-aware activity was added to the body of the TransactedReceiveScope, it would execute under the flowed transaction.

To run the sample

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

  2. To build the solution, press CTRL+SHIFT+B or select Build Solution from the Build menu.

  3. Once the build has succeeded, right-click the solution and select Set Startup Projects. From the dialog, select Multiple Startup Projects and ensure the action for both projects is Start.

  4. Press F5 or select Start Debugging from the Debug menu. Alternatively, you can press CTRL+F5 or select Start Without Debugging from the Debug menu to run without debugging.


    The server must be running prior to starting the client. The output from the console window hosting the service indicates when it has started.

Dd764465.Important(en-us,VS.100).gif Note:
The samples may already be installed on your computer. 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.