Tuesday, April 20, 2010

WCF LOB Adapter Ambient Transaction Suppression

The WCF LOB Adapter SDK literature explains some considerations when developing your own LOB adapters. One of these considerations is performance when invoked by BizTalk because loading the channel and subsequent call to LOB adapters is done within a TransactionScope.

Like the other DAL LOB adapters, for example, the WCF SQL Adapter, it is likely you will want to execute some operations outside of the ambient transaction. This will improve performance and allow you to access target systems that do not support distributed transactions.

To suppress the ambient transaction you will need to:
  1. Implement a UseAmbientTransaction binding property

  2. Wrap calls to target systems within a new transaction scope
However, the trick to instantiating the right transaction scope is in using one of the overloaded constructors that takes a TransactionScopeOption. The option you will need to suppress the ambient transaction is, you guessed it, 'Suppress'. The option to enlist in the ambient transaction is simply the 'Required' enum.

bool useAmbientXact = this.Connection.ConnectionFactory.Adapter.UseAmbientTransaction;
TransactionScopeOption xactOption = (useAmbientXact ? TransactionScopeOption.Required : TransactionScopeOption.Suppress);
using (TransactionScope xactCoOrdinator = new TransactionScope(xactOption))
{
    
// Execute target system commands here...
}

No comments:

Post a Comment