TransactionAutoComplete Property

OperationBehaviorAttribute.TransactionAutoComplete Property

Gets or sets a value that indicates whether to automatically complete the current transaction scope if no unhandled exceptions occur.

Namespace: System.ServiceModel
Assembly: System.ServiceModel (in system.servicemodel.dll)

public bool TransactionAutoComplete { get; set; }
/** @property */
public boolean get_TransactionAutoComplete ()

/** @property */
public void set_TransactionAutoComplete (boolean value)

public function get TransactionAutoComplete () : boolean

public function set TransactionAutoComplete (value : boolean)

Not applicable.

Property Value

true to complete the transaction scope automatically on successful execution of the operation; otherwise, false. The default is true.

Set the TransactionAutoComplete property to false to complete or abort transactions directly in the code for the operation.

Handled exceptions can be thrown in the course of the operation without automatically aborting the transaction. Only unhandled exceptions trigger an automatic abort.

The following code example demonstrates an operation that executes within a mandatory distributed transaction. The TransactionScopeRequired property indicates that the operation executes under a transaction scope, and the TransactionAutoComplete property indicates that if no unhandled exceptions occur the transaction scope is completed automatically. If an unhandled exception does occur, the transaction is aborted.

using System;
using System.ServiceModel;
using System.Transactions;

namespace Microsoft.WCF.Documentation
  [ServiceContract(Namespace="http://microsoft.wcf.documentation", SessionMode=SessionMode.Required)]
  public interface IBehaviorService
    string TxWork(string message);

  // Note: To use the TransactionIsolationLevel property, you 
  // must add a reference to the System.Transactions.dll assembly.
  /* The following service implementation:
   *   -- Processes messages on one thread at a time
   *   -- Creates one service object per session
   *   -- Releases the service object when the transaction commits
  public class BehaviorService : IBehaviorService, IDisposable
    Guid myID;

    public BehaviorService()
      myID = Guid.NewGuid();
        "Object "
        + myID.ToString()
        + " created.");

     * The following operation-level behaviors are specified:
     *   -- Always executes under a transaction scope.
     *   -- The transaction scope is completed when the operation terminates 
     *       without an unhandled exception.
      TransactionAutoComplete = true,
      TransactionScopeRequired = true
    public string TxWork(string message)
      // Do some transactable work.
      Console.WriteLine("TxWork called with: " + message);
      // Display transaction information.

      TransactionInformation info = Transaction.Current.TransactionInformation;
      Console.WriteLine("The distributed tx ID: {0}.", info.DistributedIdentifier);
      Console.WriteLine("The tx status: {0}.", info.Status);
      return String.Format("Hello. This was object {0}.",myID.ToString()) ;

    public void Dispose()
        "Service "
        + myID.ToString()
        + " is being recycled."

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

© 2015 Microsoft