Workflow Transactions
This topic applies to Windows Workflow Foundation 4 (WF4).
WF provides support for participating in System.Transactions transactions by using the TransactionScope activity to scope a transacted unit of work. While the System.Transactions.TransactionScope must be explicitly completed the System.Activities.Statements.TransactionScope activity implicitly calls complete on the transaction upon successful completion. Any activities that are contained in the Body of the TransactionScope activity participate in the transaction. WF can to flow transactions into a workflow through the use of the TransactedReceiveScope activity. Like the TransactionScope activity, any activity contained in the Body participates in the transaction. The distributed transaction coordinator will become involved if there is more than one database involved in the transaction. WF ensures that activities dependent on System.Transactions.Transaction.Current works with both TransactionScope and TransactedReceiveScope. If the system-provided activities do not address all requirements, custom activities can be built using the RuntimeTransactionHandle to enable advanced flow and transaction control scenarios.
In the following example, taken from the Basic TransactionScope sample, a workflow is constructed consisting of a Sequence activity that contains child activities including a TransactionScope activity. The Body activities of the TransactionScope execute under the transaction initialized by the TransactionScope activity.
static Activity ScenarioOne()
{
return new Sequence
{
Activities =
{
new WriteLine { Text = " Begin workflow" },
new TransactionScope
{
Body = new Sequence
{
Activities =
{
new WriteLine { Text = " Begin TransactionScope" },
new PrintTransactionId(),
new TransactionScopeTest(),
new WriteLine { Text = " End TransactionScope" },
},
},
},
new WriteLine { Text = " End workflow" },
}
};
}
For more information, see the basic Transactions samples, and the scenario based Transactions samples. For more information, see about using TransactedReceiveScope, see Flowing Transactions into and out of Workflow Services.
See Also
Reference
TransactionScope
TransactionScope
System.Transactions.Transaction.Current