ServiceBehaviorAttribute.TransactionTimeout Property


Gets or sets the period within which a transaction must complete.

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

public string TransactionTimeout { get; set; }

Property Value

Type: System.String

A TimeSpan object that represents the time within which transactions must complete or be automatically aborted.

Exception Condition

The value is null.


The value is less than TimeSpan.Zero or greater than TimeSpan.MaxValue.

This value sets the ChannelDispatcher.TransactionTimeout property. You can also set this property using the <serviceTimeouts> element in an application configuration file.

The following configuration file specifies a transaction timeout period of three minutes.

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

namespace Microsoft.WCF.Documentation
  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
   *   -- Does not release the service object when the transaction commits
   *   -- The isolation level is read committed.
   *   -- The transaction timeout is set to 3 minutes.
    TransactionTimeout = "00:03:00"
  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."

.NET Framework
Available since 3.0
Return to top