クリックして評価とフィードバックをお寄せください
MSDN
MSDN ライブラリ
.NET 開発
.NET Framework 3.5
.NET Framework 3.5
System.ServiceModel 名前空間

  低帯域幅での表示をオンにする
このページは次のバージョンについて記述しています。
Microsoft Visual Studio 2008/.NET Framework 3.5

その他のバージョンについては、以下の情報を参照してください。
.NET Framework クラス ライブラリ
OperationBehaviorAttribute クラス

更新 : 2007 年 11 月

サービス メソッドのローカル実行動作を指定します。

名前空間 :  System.ServiceModel
アセンブリ :  System.ServiceModel (System.ServiceModel.dll 内)
Visual Basic (宣言)
<AttributeUsageAttribute(AttributeTargets.Method)> _
Public NotInheritable Class OperationBehaviorAttribute _
    Inherits Attribute _
    Implements IOperationBehavior
Visual Basic (使用法)
Dim instance As OperationBehaviorAttribute
C#
[AttributeUsageAttribute(AttributeTargets.Method)]
public sealed class OperationBehaviorAttribute : Attribute, 
    IOperationBehavior
Visual C++
[AttributeUsageAttribute(AttributeTargets::Method)]
public ref class OperationBehaviorAttribute sealed : public Attribute, 
    IOperationBehavior
J#
/** @attribute AttributeUsageAttribute(AttributeTargets.Method) */
public final class OperationBehaviorAttribute extends Attribute implements IOperationBehavior
JScript
public final class OperationBehaviorAttribute extends Attribute implements IOperationBehavior

OperationBehaviorAttribute 属性を使用して、操作が実行されるときの操作固有の実行動作を示します (サービス レベルの実行動作を指定するには、ServiceBehaviorAttribute 属性を使用します)。

ms576447.alert_note(ja-jp,VS.90).gifメモ :

OperationBehaviorAttribute を使用して、双方向クライアント アプリケーションでコールバック コントラクト操作を設定することもできます。コールバック操作で使用する場合は、ReleaseInstanceMode プロパティが None である必要があります。そうでない場合は、InvalidOperationException 例外が実行時にスローされます。

OperationBehaviorAttribute 属性は、これがなければ開発者が自ら実装する必要のある共通機能を有効にする、Windows Communication Foundation (WCF) プログラミング モデル機能です。

  • AutoDisposeParameters プロパティは、操作に渡されたパラメータ オブジェクトを操作の完了時に破棄するかどうかを制御します。

  • TransactionAutoComplete プロパティは、未処理の例外が発生しなかった場合に、メソッドが実行されているトランザクションが自動的にコミットされるかどうかを指定します。

  • TransactionScopeRequired プロパティは、メソッドをトランザクションの中で実行する必要があるかどうかを指定します。

  • Impersonation プロパティは、サービス操作が、呼び出し元の ID を偽装できるか、偽装する必要があるか、または偽装できないかを指定します。

  • ReleaseInstanceMode プロパティは、サービス オブジェクトが、メソッドの呼び出しプロセスの間にリサイクルされるかどうかを指定します。

必須の分散トランザクション内で実行する操作のコード例を次に示します。TransactionScopeRequired プロパティは、メソッドが呼び出し元のトランザクションの下で実行されることを示し、TransactionAutoComplete プロパティは、未処理の例外が発生しない場合にトランザクションが自動的にコミットすることを示します。未処理の例外が発生すると、トランザクションは中止されます。

C#
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
コミュニティ コンテンツ   コミュニティ コンテンツとは
新しいコンテンツの追加 RSS  注釈
Processing
© 2009 Microsoft Corporation. All rights reserved. 使用条件  |  商標  |  プライバシー
Page view tracker