TransactionFlowAttribute 類別

定義

指定服務作業是否接受來自用戶端的傳入異動。

public ref class TransactionFlowAttribute sealed : Attribute, System::ServiceModel::Description::IOperationBehavior
[System.AttributeUsage(System.AttributeTargets.Method)]
public sealed class TransactionFlowAttribute : Attribute, System.ServiceModel.Description.IOperationBehavior
[<System.AttributeUsage(System.AttributeTargets.Method)>]
type TransactionFlowAttribute = class
    inherit Attribute
    interface IOperationBehavior
Public NotInheritable Class TransactionFlowAttribute
Inherits Attribute
Implements IOperationBehavior
繼承
TransactionFlowAttribute
屬性
實作

範例

在下列程式碼範例中,會示範如何在作業層級搭配 TransactionFlowOption 類別來使用這個列舉型別。

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."  
      );  
    }  
  }  
}  

備註

TransactionFlowAttribute 是以宣告方式將特定異動流程原則和服務作業產生關聯的屬性。 此屬性 (Attribute) 的 TransactionFlowOption 屬性 (Property) 指定個別作業是否接受來自用戶端的流動交易,抑或是作業需要用戶端一律流動交易。 TransactionFlowAttribute 也可用來當成作業行為,以程式設計的方式將交易流程原則和指定作業產生關聯。 在此情況下,應該將它新增至 Behaviors 作業描述上的集合。

注意

每個使用 OperationContract 之方法的 TransactionFlowAttribute 都必須提供完整的 Action 字串。 不支援 "*" 值。

建構函式

TransactionFlowAttribute(TransactionFlowOption)

初始化 TransactionFlowAttribute 類別的新執行個體。

屬性

Transactions

取得值,這個值表示是否支援傳入交易。

TypeId

在衍生類別中實作時,取得這個 Attribute 的唯一識別碼。

(繼承來源 Attribute)

方法

Equals(Object)

傳回值,這個值指出此執行個體是否與指定的物件相等。

(繼承來源 Attribute)
GetHashCode()

傳回這個執行個體的雜湊碼。

(繼承來源 Attribute)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
IsDefaultAttribute()

在衍生類別中覆寫時,表示這個執行個體的值是衍生類別的預設值。

(繼承來源 Attribute)
Match(Object)

在衍生類別中覆寫時,會傳回值,表示這個執行個體是否等於指定物件。

(繼承來源 Attribute)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

明確介面實作

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。

(繼承來源 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

擷取物件的類型資訊,可以用來取得介面的類型資訊。

(繼承來源 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

擷取物件提供的類型資訊介面數目 (0 或 1)。

(繼承來源 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供物件所公開的屬性和方法的存取權。

(繼承來源 Attribute)
IOperationBehavior.AddBindingParameters(OperationDescription, BindingParameterCollection)

將額外參數 (設定) 新增至繫結內容以支援這個作業的行為。 這個方法無法被繼承。

IOperationBehavior.ApplyClientBehavior(OperationDescription, ClientOperation)

為屬性標記的方法附加屬性功能至 ProxyOperation 物件。 這個方法無法被繼承。

IOperationBehavior.ApplyDispatchBehavior(OperationDescription, DispatchOperation)

為屬性標記的方法附加屬性功能至 DispatchOperation 物件。 這個方法無法被繼承。

IOperationBehavior.Validate(OperationDescription)

確認作業可支援此行為。 這個方法無法被繼承。

適用於

另請參閱