IClientMessageInspector Interface
Defines a message inspector object that can be added to the MessageInspectors collection to view or modify messages.
Assembly: System.ServiceModel (in System.ServiceModel.dll)
The IClientMessageInspector type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | AfterReceiveReply | Enables inspection or modification of a message after a reply message is received but prior to passing it back to the client application. |
![]() | BeforeSendRequest | Enables inspection or modification of a message before a request message is sent to a service. |
Implement the IClientMessageInspector interface and add it to the MessageInspectors collection to inspect or modify messages as they pass through a client object. For details, see ClientRuntime.
The following code example shows an implementation that writes strings to the console when the implementation is called.
#Region "IClientMessageInspector Members" Public Sub AfterReceiveReply(ByRef reply As System.ServiceModel.Channels.Message, _ ByVal correlationState As Object) Implements IClientMessageInspector.AfterReceiveReply Console.WriteLine("IClientMessageInspector.AfterReceiveReply called.") Console.WriteLine("Message: {0}", reply.ToString()) End Sub Public Function BeforeSendRequest(ByRef request As System.ServiceModel.Channels.Message, _ ByVal channel As IClientChannel) As Object Implements IClientMessageInspector.BeforeSendRequest Console.WriteLine("IClientMessageInspector.BeforeSendRequest called.") Return Nothing End Function
The following code example shows how to use an System.ServiceModel.Description.IEndpointBehavior to insert the client message inspector in the client endpoint.
#Region "IEndpointBehavior Members" Public Sub AddBindingParameters(ByVal endpoint As ServiceEndpoint, ByVal bindingParameters _ As BindingParameterCollection) Implements IEndpointBehavior.AddBindingParameters Return End Sub Public Sub ApplyClientBehavior(ByVal endpoint As ServiceEndpoint, ByVal clientRuntime As ClientRuntime) _ Implements IEndpointBehavior.ApplyClientBehavior clientRuntime.MessageInspectors.Add(New Inspector()) For Each op As ClientOperation In clientRuntime.Operations op.ParameterInspectors.Add(New Inspector()) Next op End Sub Public Sub ApplyDispatchBehavior(ByVal endpoint As ServiceEndpoint, ByVal endpointDispatcher As _ EndpointDispatcher) Implements IEndpointBehavior.ApplyDispatchBehavior endpointDispatcher.DispatchRuntime.MessageInspectors.Add(New Inspector()) For Each op As DispatchOperation In endpointDispatcher.DispatchRuntime.Operations op.ParameterInspectors.Add(New Inspector()) Next op End Sub Public Sub Validate(ByVal endpoint As ServiceEndpoint) Implements IEndpointBehavior.Validate Return End Sub
Finally, the following code example shows how to modify the client configuration file to use the endpoint behavior with a particular endpoint.
<client>
<endpoint
address="http://localhost:8080/SampleService"
behaviorConfiguration="clientInspectorsAdded"
binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_ISampleService"
contract="ISampleService"
name="WSHttpBinding_ISampleService"
>
</endpoint>
</client>
<behaviors>
<endpointBehaviors>
<behavior name="clientInspectorsAdded">
<clientInterceptors />
</behavior>
</endpointBehaviors>
</behaviors>
<extensions>
<behaviorExtensions>
<add
name="clientInterceptors"
type="Microsoft.WCF.Documentation.InspectorInserter, HostApplication, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"
/>
</behaviorExtensions>
</extensions>
<client>
<endpoint
address="http://localhost:8080/SampleService"
behaviorConfiguration="clientInspectorsAdded"
binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_ISampleService"
contract="ISampleService"
name="WSHttpBinding_ISampleService"
>
</endpoint>
</client>
<behaviors>
<endpointBehaviors>
<behavior name="clientInspectorsAdded">
<clientInterceptors />
</behavior>
</endpointBehaviors>
</behaviors>
<extensions>
<behaviorExtensions>
<add
name="clientInterceptors"
type="Microsoft.WCF.Documentation.InspectorInserter, HostApplication, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"
/>
</behaviorExtensions>
</extensions>
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.
