更新 : 2007 年 11 月
サービス メソッドのローカル実行動作を指定します。
名前空間 :
System.ServiceModel
アセンブリ :
System.ServiceModel (System.ServiceModel.dll 内)
<AttributeUsageAttribute(AttributeTargets.Method)> _
Public NotInheritable Class OperationBehaviorAttribute _
Inherits Attribute _
Implements IOperationBehavior
Dim instance As OperationBehaviorAttribute
[AttributeUsageAttribute(AttributeTargets.Method)]
public sealed class OperationBehaviorAttribute : Attribute,
IOperationBehavior
[AttributeUsageAttribute(AttributeTargets::Method)]
public ref class OperationBehaviorAttribute sealed : public Attribute,
IOperationBehavior
/** @attribute AttributeUsageAttribute(AttributeTargets.Method) */
public final class OperationBehaviorAttribute extends Attribute implements IOperationBehavior
public final class OperationBehaviorAttribute extends Attribute implements IOperationBehavior
OperationBehaviorAttribute 属性を使用して、操作が実行されるときの操作固有の実行動作を示します (サービス レベルの実行動作を指定するには、ServiceBehaviorAttribute 属性を使用します)。
OperationBehaviorAttribute 属性は、これがなければ開発者が自ら実装する必要のある共通機能を有効にする、Windows Communication Foundation (WCF) プログラミング モデル機能です。
必須の分散トランザクション内で実行する操作のコード例を次に示します。TransactionScopeRequired プロパティは、メソッドが呼び出し元のトランザクションの下で実行されることを示し、TransactionAutoComplete プロパティは、未処理の例外が発生しない場合にトランザクションが自動的にコミットすることを示します。未処理の例外が発生すると、トランザクションは中止されます。
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]
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
)]
[TransactionFlow(TransactionFlowOption.Mandatory)]
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..::.OperationBehaviorAttribute
この型のすべてのパブリック static (Visual Basic では Shared) メンバは、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
Windows Vista, Windows XP SP2, Windows Server 2003
.NET Framework および .NET Compact Framework では、各プラットフォームのすべてのバージョンはサポートしていません。サポートされているバージョンについては、「.NET Framework システム要件」を参照してください。
.NET Framework
サポート対象 : 3.5、3.0
参照