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

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

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

更新 : 2007 年 11 月

サービス コントラクトの実装の内部実行動作を指定します。

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

ServiceBehaviorAttribute 属性をサービスの実装に適用して、サービス全体の実行動作を指定します (メソッド レベルの実行動作を指定するには、OperationBehaviorAttribute 属性を使用します)。この属性を適用できるのはサービスの実装だけです。実施例については、「サービス : 動作サンプル」を参照してください。

ServiceBehaviorAttribute プロパティは、共通機能を有効にする Windows Communication Foundation (WCF) プログラミング モデルの機能で、このプロパティがない場合は、開発者がこの共通機能を実装する必要があります。これらの動作、その他の動作の詳細については、「サービスのランタイム動作の指定」を参照してください。次に示すいくつかのプロパティが設定される基になるランタイム プロパティの詳細については、「ServiceHost とサービス モデル レイヤの拡張」を参照してください。

  • AddressFilterMode プロパティは、ディスパッチャ システムが、要求を処理するエンドポイントを検索するために使用するフィルタの種類を指定します。

  • AutomaticSessionShutdown プロパティは、チャネルが閉じられ、残っているすべてのメッセージの処理をサービスが終了した時点でセッションを自動的に閉じます。

  • ConcurrencyMode プロパティは、内部スレッド モデルを制御して、再入可能またはマルチスレッド サービスのサポートを有効にします。

  • ConfigurationName プロパティは、構成ファイル内で <service> 要素の name 属性で使用する名前を宣言するために使用されます。

  • IgnoreExtensionDataObject プロパティは、メッセージの処理では必要がない余分なシリアル化情報をランタイムが無視できるようにします。

  • IncludeExceptionDetailInFaults プロパティは、サービス内の未処理の例外を SOAP エラーとして返すかどうかを指定します。これは、デバッグのみを目的としています。

  • InstanceContextMode プロパティは、クライアントとのメッセージ交換時にサービスとサービス オブジェクトをリサイクルするかどうかを指定します。また、リサイクルする場合は、どの時点でリサイクルするかを指定します。

  • MaxItemsInObjectGraph プロパティは、シリアル化されるオブジェクト グラフ内の項目数を制限します。

  • Name プロパティと Namespace プロパティは、サービス要素の WSDL 表現の名前と名前空間を制御します。

  • ReleaseServiceInstanceOnTransactionComplete プロパティは、トランザクションの完了時にサービス オブジェクトをリサイクルするかどうかを指定します。

  • TransactionAutoCompleteOnSessionClose プロパティは、セッションの終了時に未解決のトランザクションを完了するかどうかを指定します。

  • TransactionIsolationLevel プロパティは、コントラクトがサポートするトランザクションの分離レベルを指定します。

  • TransactionTimeout プロパティは、トランザクションを完了しなければならない期間を指定します。この期間内に完了しない場合、トランザクションは中止されます。

  • UseSynchronizationContext プロパティは、受信したメソッド呼び出しをユーザー インターフェイス スレッドと自動的に同期するかどうかを示します。

  • ValidateMustUnderstand プロパティは、MustUnderstand としてマークされた SOAP ヘッダーが間違いなく理解されたことを確認する必要があるかどうかをシステムに通知します。

IncludeExceptionDetailInFaults プロパティは、アプリケーション構成ファイルを使用して設定することもできます。詳細については、IncludeExceptionDetailInFaults のトピックを参照してください。

次のコード例は、ServiceBehaviorAttribute プロパティを示しています。BehaviorService クラスは、次のことを示すために ServiceBehaviorAttribute 属性を使用します。

  • サービス オブジェクトは、トランザクションの完了時にリサイクルされます。

  • セッションごとに 1 つのサービス オブジェクトが存在します。

  • サービスはシングル スレッドであり、再入呼び出しをサポートしません。

さらに、OperationBehaviorAttribute 値は操作レベルで、TxWork メソッドがフロー トランザクションに自動的に登録するかまたはこの処理のための新しいトランザクションを作成するかどうか、および未処理の例外が発生しない場合にトランザクションが自動的にコミットされるかどうかを示します。

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:
     *   -- The executing transaction is committed when
     *        the operation completes without an 
     *        unhandled exception
     *   -- Always executes under a flowed transaction.
     */
    [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."
      );
    }
  }
}

次のコード例が適切に動作するには、基になるバインディングでフロー トランザクションがサポートされている必要があります。たとえば、WSHttpBinding を使用するフロー トランザクションをサポートするには、コードまたはアプリケーション構成ファイル内で TransactionFlow プロパティを true に設定します。次のコード例は、前のサンプルの構成ファイルを示しています。

<configuration>
  <system.serviceModel>
    <services>
      <service  
        name="Microsoft.WCF.Documentation.BehaviorService" 
        behaviorConfiguration="metadataAndDebugEnabled"
      >
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8080/SampleService"/>
          </baseAddresses>
        </host>
        <!--
          Note:
            This example code uses the WSHttpBinding to support transactions using the 
            WS-AtomicTransactions (WS-AT) protocol. WSHttpBinding is configured to use the  
            protocol, but the protocol is not enabled on some computers. Use the xws_reg -wsat+ 
            command to enable the WS-AtomicTransactions protocol in the MSDTC service.          
          -->
        <endpoint 
           contract="Microsoft.WCF.Documentation.IBehaviorService"
           binding="wsHttpBinding"
           bindingConfiguration="wsHttpBindingWithTXFlow"
           address="http://localhost:8080/BehaviorService"
          />
        <endpoint 
               contract="Microsoft.WCF.Documentation.IBehaviorService"
               binding="netTcpBinding"
               bindingConfiguration="netTcpBindingWithTXFlow"
               address="net.tcp://localhost:8081/BehaviorService"
          />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="metadataAndDebugEnabled">
          <serviceDebug
            includeExceptionDetailInFaults="true"
          />
          <serviceMetadata
            httpGetEnabled="true"
            httpGetUrl=""
          />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <!-- binding configuration - configures a WSHttpBinding to require transaction flow -->
    <bindings>
      <wsHttpBinding>
        <binding name="wsHttpBindingWithTXFlow" transactionFlow="true" />
      </wsHttpBinding>
      <netTcpBinding>
        <binding name="netTcpBindingWithTXFlow" transactionFlow="true" />
      </netTcpBinding>
    </bindings>
  </system.serviceModel>
</configuration>

System..::.Object
  System..::.Attribute
    System.ServiceModel..::.ServiceBehaviorAttribute
この型のすべてのパブリック 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