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

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

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

更新 : 2007 年 11 月

サービス アプリケーションで受信および送信アプリケーション メッセージのカスタム検査または変更を可能にするメソッドを定義します。

名前空間 :  System.ServiceModel.Dispatcher
アセンブリ :  System.ServiceModel (System.ServiceModel.dll 内)
Visual Basic (宣言)
Public Interface IDispatchMessageInspector
Visual Basic (使用法)
Dim instance As IDispatchMessageInspector
C#
public interface IDispatchMessageInspector
Visual C++
public interface class IDispatchMessageInspector
J#
public interface IDispatchMessageInspector
JScript
public interface IDispatchMessageInspector

要求メッセージを操作にディスパッチする前に、または応答メッセージを呼び出し元に返す前に、受信または送信アプリケーション メッセージを検査または変更するには、IDispatchMessageInspector を実装します。メッセージの宛先の操作を呼び出す前にメッセージをインターセプトする必要のあるシナリオは、数多くあります。たとえば、受信アプリケーション メッセージをログに記録したり、メッセージ ヘッダーに基づいてなんらかの機能を実行したりすることが考えられます。

通常、メッセージ インスペクタは、サービス動作 (System.ServiceModel.Description..::.IServiceBehavior)、エンドポイント動作 (System.ServiceModel.Description..::.IEndpointBehavior)、またはコントラクト動作 (System.ServiceModel.Description..::.IContractBehavior) により挿入されます。その後、動作は、メッセージ インスペクタを DispatchRuntime..::.MessageInspectors コレクションに追加します。動作を使用したランタイムの拡張の詳細については、「ServiceHost とサービス モデル レイヤの拡張」を参照してください。

  • AfterReceiveRequest メソッドを使用すると、メッセージを受信した後で、目的の操作にメッセージをディスパッチする前に、カスタム動作を実行できます。

  • BeforeSendReply メソッドを使用すると、操作から返った後で、応答を送信する前に、カスタム動作を実行できます。

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

操作が一方向か要求/応答かに関係なく、IDispatchMessageInspector オブジェクトは常に、メッセージ ディスパッチの間の同じ位置で呼び出されます。

次のコード例では、呼び出されるときにコンソールに文字列を書き出す基本的な IDispatchMessageInspector を示します。

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

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

次のコード例では、InspectorIDispatchMessageInspectorDispatchRuntime..::.MessageInspectors に追加する IServiceBehavior の実装を示します。

C#
#region IServiceBehavior Members
public void AddBindingParameters(
  ServiceDescription serviceDescription, 
  ServiceHostBase serviceHostBase, 
  System.Collections.ObjectModel.Collection<ServiceEndpoint> endpoints, 
  BindingParameterCollection bindingParameters
)
{ return; }

public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
{
  foreach (ChannelDispatcher chDisp in serviceHostBase.ChannelDispatchers)
  {
    foreach (EndpointDispatcher epDisp in chDisp.Endpoints)
    {
      epDisp.DispatchRuntime.MessageInspectors.Add(new Inspector());
      foreach (DispatchOperation op in epDisp.DispatchRuntime.Operations)
        op.ParameterInspectors.Add(new Inspector());
    }
  }
}

次のコード例では、アプリケーション構成ファイルを使用して、InspectorIDispatchMessageInspector を挿入するサービス動作を読み込む方法を示しています。

<configuration>
  <system.serviceModel>
    <services>
      <service 
        name="Microsoft.WCF.Documentation.SampleService"
        behaviorConfiguration="inspectorBehavior">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8080/SampleService" />
          </baseAddresses>
        </host>
        <endpoint
          address=""
          binding="wsHttpBinding"
          contract="Microsoft.WCF.Documentation.ISampleService"
        />

      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="inspectorBehavior">
          <serviceInspectors />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <extensions>
      <behaviorExtensions>
        <add 
          name="serviceInspectors" 
          type="Microsoft.WCF.Documentation.InspectorInserter, 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
コミュニティ コンテンツ   コミュニティ コンテンツとは
新しいコンテンツの追加 RSS  注釈
Processing
© 2009 Microsoft Corporation. All rights reserved. 使用条件  |  商標  |  プライバシー
Page view tracker