TransactionFlowAttribute 類別
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
指定服務作業是否接受來自用戶端的傳入異動。
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
- 繼承
- 屬性
- 實作
在下列程式碼範例中,會示範如何在作業層級搭配 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
字串。 不支援 "*" 值。
Transactions |
取得值,這個值表示是否支援傳入交易。 |
Type |
在衍生類別中實作時,取得這個 Attribute 的唯一識別碼。 (繼承來源 Attribute) |
Equals(Object) |
傳回值,這個值指出此執行個體是否與指定的物件相等。 (繼承來源 Attribute) |
Get |
傳回這個執行個體的雜湊碼。 (繼承來源 Attribute) |
Get |
取得目前執行個體的 Type。 (繼承來源 Object) |
Is |
在衍生類別中覆寫時,表示這個執行個體的值是衍生類別的預設值。 (繼承來源 Attribute) |
Match(Object) |
在衍生類別中覆寫時,會傳回值,表示這個執行個體是否等於指定物件。 (繼承來源 Attribute) |
Memberwise |
建立目前 Object 的淺層複製。 (繼承來源 Object) |
To |
傳回代表目前物件的字串。 (繼承來源 Object) |
_Attribute. |
將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。 (繼承來源 Attribute) |
_Attribute. |
擷取物件的類型資訊,可以用來取得介面的類型資訊。 (繼承來源 Attribute) |
_Attribute. |
擷取物件提供的類型資訊介面數目 (0 或 1)。 (繼承來源 Attribute) |
_Attribute. |
提供物件所公開的屬性和方法的存取權。 (繼承來源 Attribute) |
IOperation |
將額外參數 (設定) 新增至繫結內容以支援這個作業的行為。 這個方法無法被繼承。 |
IOperation |
為屬性標記的方法附加屬性功能至 |
IOperation |
為屬性標記的方法附加屬性功能至 DispatchOperation 物件。 這個方法無法被繼承。 |
IOperation |
確認作業可支援此行為。 這個方法無法被繼承。 |
產品 | 版本 |
---|---|
.NET Framework | 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |