TransactionFlowAttribute 類別

定義

指定服務作業是否接受來自用戶端的傳入異動。Specifies whether a service operation accepts incoming transactions from a client.

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 類別來使用這個列舉型別。The following code example shows 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."  
      );  
    }  
  }  
}  

備註

TransactionFlowAttribute 是以宣告方式將特定異動流程原則和服務作業產生關聯的屬性。The TransactionFlowAttribute is an attribute used declaratively to associate a specific transaction flow policy with a service operation. 此屬性 (Attribute) 的 TransactionFlowOption 屬性 (Property) 指定個別作業是否接受來自用戶端的流動交易,抑或是作業需要用戶端一律流動交易。The TransactionFlowOption property of this attribute specifies whether the respective operation accepts a transaction flowed from the client, or if the operation requires the client to always flow a transaction. TransactionFlowAttribute 也可用來當成作業行為,以程式設計的方式將交易流程原則和指定作業產生關聯。The TransactionFlowAttribute can also be used as an operation behavior to programmatically associate a transaction flow policy with a specific operation. 在此情況下,應該將它新增至作業 Behaviors 描述上的集合。In this case, it should be added to the Behaviors collection on the operation's description.

注意

每個使用 OperationContract 之方法的 TransactionFlowAttribute 都必須提供完整的 Action 字串。The OperationContract for each method that uses the TransactionFlowAttribute must provide a fully-qualified Action string. 不支援 "*" 值。A value of "*" is not supported.

建構函式

TransactionFlowAttribute(TransactionFlowOption)

初始化 TransactionFlowAttribute 類別的新執行個體。Initializes a new instance of the TransactionFlowAttribute class.

屬性

Transactions

取得值,這個值表示是否支援傳入交易。Gets a value that indicates whether the incoming transaction is supported.

TypeId

在衍生類別中實作時,取得這個 Attribute 的唯一識別碼。When implemented in a derived class, gets a unique identifier for this Attribute.

(繼承來源 Attribute)

方法

Equals(Object)

傳回值,這個值指出此執行個體是否與指定的物件相等。Returns a value that indicates whether this instance is equal to a specified object.

(繼承來源 Attribute)
GetHashCode()

傳回這個執行個體的雜湊碼。Returns the hash code for this instance.

(繼承來源 Attribute)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
IsDefaultAttribute()

在衍生類別中覆寫時,表示這個執行個體的值是衍生類別的預設值。When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.

(繼承來源 Attribute)
Match(Object)

在衍生類別中覆寫時,會傳回值,表示這個執行個體是否等於指定物件。When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(繼承來源 Attribute)
MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)

明確介面實作

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

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。Maps a set of names to a corresponding set of dispatch identifiers.

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

擷取物件的類型資訊,可以用來取得介面的類型資訊。Retrieves the type information for an object, which can be used to get the type information for an interface.

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

擷取物件提供的類型資訊介面數目 (0 或 1)。Retrieves the number of type information interfaces that an object provides (either 0 or 1).

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

提供物件所公開的屬性和方法的存取權。Provides access to properties and methods exposed by an object.

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

將額外參數 (設定) 新增至繫結內容以支援這個作業的行為。Adds extra parameters (settings) to the binding context to support this operation's behavior. 這個方法無法被繼承。This method cannot be inherited.

IOperationBehavior.ApplyClientBehavior(OperationDescription, ClientOperation)

為屬性標記的方法附加屬性功能至 ProxyOperation 物件。Attaches the attribute functionality to the ProxyOperation object for the method that the attribute marks. 這個方法無法被繼承。This method cannot be inherited.

IOperationBehavior.ApplyDispatchBehavior(OperationDescription, DispatchOperation)

為屬性標記的方法附加屬性功能至 DispatchOperation 物件。Attaches the attribute functionality to the DispatchOperation object for the method that the attribute marks. 這個方法無法被繼承。This method cannot be inherited.

IOperationBehavior.Validate(OperationDescription)

確認作業可支援此行為。Verifies that the operation can support this behavior. 這個方法無法被繼承。This method cannot be inherited.

適用於