Nesting of TransactionScope within a service
This sample consists of two scenarios that run showing how to handle TransactionScope activity instances within a service. First the transaction is initiated using the TransactionScope activity to create a new transaction on the client and TransactedReceiveScope to receive and scope the lifetime of the transaction on the server. The first scenario within the service runs a secondary TransactionScope activity to demonstrate the nesting of the TransactionScope activities within the service. The second scenario shows how time-outs are respected within the nested TransactionScope activities.
The client application runs a workflow that starts a TransactionScope activity, 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. It does this once for each service scenario.
The server project is hosted in WorkflowServiceHost, which creates the endpoint to listen for the message from the client. The workflow is centered on the TransactedReceiveScope, which receives the flowed transaction from the client, prints the distributed transaction ID and then executes a second TransactionScope activity. In the first scenario, the transaction is completed successfully. In the second scenario, the body of the TransactionScope activity is a five-second delay and the time-out for the transaction is set to two seconds. When the transaction times out the transaction is aborted.
To run the sample
Open the TransactionServiceExample.sln solution in Visual Studio 2010.
To build the solution, press CTRL+SHIFT+B or select Build Solution from the Build menu.
Once the build has succeeded, right-click the solution and select Set Startup Projects. From the dialog box, select Multiple Startup Projects and ensure the action for both projects is Start.
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 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.