.NET Framework クラス ライブラリ
IEndpointBehavior..::.ApplyDispatchBehavior メソッド

更新 : 2007 年 11 月

エンドポイント全体にわたってサービスの変更または拡張を実装します。

名前空間 :  System.ServiceModel.Description
アセンブリ :  System.ServiceModel (System.ServiceModel.dll 内)
構文

Visual Basic (宣言)
Sub ApplyDispatchBehavior ( _
    endpoint As ServiceEndpoint, _
    endpointDispatcher As EndpointDispatcher _
)
Visual Basic (使用法)
Dim instance As IEndpointBehavior
Dim endpoint As ServiceEndpoint
Dim endpointDispatcher As EndpointDispatcher

instance.ApplyDispatchBehavior(endpoint, _
    endpointDispatcher)
C#
void ApplyDispatchBehavior(
    ServiceEndpoint endpoint,
    EndpointDispatcher endpointDispatcher
)
Visual C++
void ApplyDispatchBehavior(
    ServiceEndpoint^ endpoint, 
    EndpointDispatcher^ endpointDispatcher
)
J#
void ApplyDispatchBehavior(
    ServiceEndpoint endpoint,
    EndpointDispatcher endpointDispatcher
)
JScript
function ApplyDispatchBehavior(
    endpoint : ServiceEndpoint, 
    endpointDispatcher : EndpointDispatcher
)

パラメータ

endpoint
型 : System.ServiceModel.Description..::.ServiceEndpoint
コントラクトを公開するエンドポイント。
endpointDispatcher
型 : System.ServiceModel.Dispatcher..::.EndpointDispatcher
変更または拡張対象のエンドポイント ディスパッチャ。
解説

エンドポイントのすべてのメッセージまたは特定の操作について、サービス ランタイムを表示、変更、または拡張するには、ApplyDispatchBehavior メソッドを実装します。サービス アプリケーションで実行できるカスタマイズの詳細については、System.ServiceModel.Dispatcher..::.DispatchRuntime および System.ServiceModel.Dispatcher..::.DispatchOperation を参照してください。

動作をクライアント アプリケーションでのみ使用する場合は、ApplyDispatchBehavior メソッドで NotImplementedException 例外をスローさせることをお勧めします。

コールバック コントラクト (各方向に 1 つずつの操作) を使用するときは、説明に同じ名前の操作が 2 つ存在する場合がありますので注意してください。操作の反復が必要な場合は、エンドポイント System.ServiceModel.Dispatcher..::.DispatchRuntime と、DispatchRuntime..::.CallbackClientRuntime プロパティによって返されるエンドポイント間で、メッセージの方向を関連付ける必要があります。

また、既に他の動作によって一部の操作が追加されるか、ランタイムから削除されている可能性があるので、DispatchRuntime..::.Operations プロパティにある System.ServiceModel.Dispatcher..::.DispatchOperation オブジェクトと同じ数の操作が説明に存在するという保証はありません。


サービス アプリケーションで System.ServiceModel.Dispatcher..::.IDispatchMessageInspector オブジェクトを追加するエンドポイント動作の実装を次のコード例に示します。この場合、EndpointBehaviorMessageInspector クラスは、受信および送信メッセージを調べるための System.ServiceModel.Dispatcher..::.IDispatchMessageInspector、動作が適用されるすべてのエンドポイントの検査システムにインスペクタ クラスを挿入するための IEndpointBehavior インターフェイス、およびアプリケーション構成ファイルを使用してメッセージ インスペクタの動作ができるようにするための System.ServiceModel.Configuration..::.BehaviorExtensionElement を実装します。

最初にメッセージ インスペクタを実装します。

C#
// IDispatchMessageInspector Members

public object AfterReceiveRequest(ref System.ServiceModel.Channels.Message request, IClientChannel channel, InstanceContext instanceContext)
{
  Console.WriteLine("AfterReceiveRequest called.");
  return null;
}

public void BeforeSendReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
{
  Console.WriteLine("BeforeSendReply called.");
}

メッセージ インスペクタを DispatchRuntime..::.MessageInspectors プロパティに追加する ApplyDispatchBehavior メソッドの使用法を次のコード例に示します。

C#
// IEndpointBehavior Members
public void AddBindingParameters(ServiceEndpoint serviceEndpoint, System.ServiceModel.Channels.BindingParameterCollection bindingParameters)
{
  return;
}

public void ApplyClientBehavior(ServiceEndpoint serviceEndpoint, ClientRuntime behavior)
{
  throw new Exception("The EndpointBehaviorMessageInspector is not used in client applications.");
}

public void ApplyDispatchBehavior(ServiceEndpoint serviceEndpoint, EndpointDispatcher endpointDispatcher)
{
  endpointDispatcher.DispatchRuntime.MessageInspectors.Add(new EndpointBehaviorMessageInspector());
}

public void Validate(ServiceEndpoint serviceEndpoint)
{
  return;
}

構成ファイルからメッセージ インスペクタ動作を使用できるようにするための System.ServiceModel.Configuration..::.BehaviorExtensionElement の実装を次のコード例に示します。

C#
// BehaviorExtensionElement members
public override Type BehaviorType
{
  get { return typeof(EndpointBehaviorMessageInspector); }
}

protected override object CreateBehavior()
{
  return new EndpointBehaviorMessageInspector();
}

最後に、前の例を構成から使用できるようにする方法を次の構成ファイルに示します。

xml
<configuration>
  <system.serviceModel>
    <services>
      <service 
        name="Microsoft.WCF.Documentation.SampleService"
        behaviorConfiguration="metadataSupport"
      >
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8080/ServiceMetadata" />
          </baseAddresses>
        </host>
        <endpoint
          address="/SampleService"
          binding="wsHttpBinding"
          behaviorConfiguration="withMessageInspector" 
          contract="Microsoft.WCF.Documentation.ISampleService"
        />
        <endpoint
           address="mex"
           binding="mexHttpBinding"
           contract="IMetadataExchange"
        />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
      <behavior name="metadataSupport">
        <serviceMetadata httpGetEnabled="true" httpGetUrl=""/>
      </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="withMessageInspector">
          <endpointMessageInspector />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <extensions>
      <behaviorExtensions>
        <add 
          name="endpointMessageInspector"
          type="Microsoft.WCF.Documentation.EndpointBehaviorMessageInspector, HostApplication, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"
        />
      </behaviorExtensions>
    </extensions>
  </system.serviceModel>
</configuration>
アクセス許可

  • 直前の呼び出し元に対する完全な信頼。このメンバは、部分的に信頼されているコードから使用することはできません。詳細については、「部分信頼コードからのライブラリの使用」を参照してください。
プラットフォーム

Windows Vista, Windows XP SP2, Windows Server 2003

.NET Framework および .NET Compact Framework では、各プラットフォームのすべてのバージョンはサポートしていません。サポートされているバージョンについては、「.NET Framework システム要件」を参照してください。
バージョン情報

.NET Framework

サポート対象 : 3.5、3.0
参照

参照

タグ :


Page view tracker