IDispatchMessageInspector Interface
Defines the methods that enable custom inspection or modification of inbound and outbound application messages in service applications.
Assembly: System.ServiceModel (in System.ServiceModel.dll)
The IDispatchMessageInspector type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | AfterReceiveRequest | Called after an inbound message has been received but before the message is dispatched to the intended operation. |
![]() | BeforeSendReply | Called after the operation has returned but before the reply message is sent. |
Implement IDispatchMessageInspector to inspect or modify inbound or outbound application messages either prior to dispatching a request message to an operation or before returning a reply message to a caller. There are a large number of scenarios that require intercepting messages prior to invoking the operation for which it is destined. For example, you can log incoming application messages or perform some feature based on a message header.
Typically, message inspectors are inserted by a service behavior (System.ServiceModel.Description::IServiceBehavior), an endpoint behavior (System.ServiceModel.Description::IEndpointBehavior), or a contract behavior (System.ServiceModel.Description::IContractBehavior). The behavior then adds the message inspector to the DispatchRuntime::MessageInspectors collection. For more information about extending the runtime using behaviors, see Extending ServiceHost and the Dispatcher.
The AfterReceiveRequest method enables custom behavior after receiving the message but before dispatching it to the intended operation.
The BeforeSendReply method enables custom behavior after the operation returns but before the reply is sent.
Note |
|---|
IDispatchMessageInspector objects are always called at the same point during message dispatch regardless of whether an operation is one-way or request-reply. |
The following code example shows a basic IDispatchMessageInspector that writes a string to the console when it is invoked.
The following code example shows the implementation of an IServiceBehavior that adds the InspectorIDispatchMessageInspector to the DispatchRuntime::MessageInspectors collection.
The following code example shows the use of an application configuration file to load the service behavior that inserts the 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 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
