TransactionFlowAttribute Class
TOC
Collapse the table of content
Expand the table of content

TransactionFlowAttribute Class

Specifies the willingness of a service operation to accept incoming transactions from a client.

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

[AttributeUsageAttribute(AttributeTargets.Method)] 
public sealed class TransactionFlowAttribute : Attribute, IOperationBehavior
/** @attribute AttributeUsageAttribute(AttributeTargets.Method) */ 
public final class TransactionFlowAttribute extends Attribute implements IOperationBehavior
AttributeUsageAttribute(AttributeTargets.Method) 
public final class TransactionFlowAttribute extends Attribute implements IOperationBehavior
Not applicable.

The TransactionFlowAttribute is an attribute used declaratively to associate a specific transaction flow policy with a service operation. The TransactionFlowOption property of this attribute specifies whether the respective operation may accept a transaction flowed from the client, or if the operation requires the client to always flow a transaction. The TransactionFlowAttribute can also be used as an operation behavior to programmatically associate a transaction flow policy with a specific operation. In this case, it should be added to the Behaviors collection on the operation’s description.

NoteNote:

The OperationContract for each method that uses the TransactionFlowAttribute must provide a fully qualified Action string. A value of "*" is not supported.

The following code example demonstrates the use of this enumeration together with the TransactionFlowOption class at the operation level.

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

namespace Microsoft.WCF.Documentation
{
  [ServiceContract(
    Namespace="http://microsoft.wcf.documentation", 
    SessionMode=SessionMode.Required
  )]
  public interface IBehaviorService
  {
    [OperationContract]
    [TransactionFlow(TransactionFlowOption.Mandatory)]
    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
   */
  [ServiceBehavior(
    ConcurrencyMode=ConcurrencyMode.Single,
    InstanceContextMode=InstanceContextMode.PerSession,
    ReleaseServiceInstanceOnTransactionComplete=true
  )]
  public class BehaviorService : IBehaviorService, IDisposable
  {
    Guid myID;

    public BehaviorService()
    {
      myID = Guid.NewGuid();
      Console.WriteLine(
        "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.
    /*
    [OperationBehavior(
      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()
    {
      Console.WriteLine(
        "Service "
        + myID.ToString()
        + " is being recycled."
      );
    }
  }
}

System.Object
   System.Attribute
    System.ServiceModel.TransactionFlowAttribute

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

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

ADD
Show:
© 2016 Microsoft