IClientMessageInspector Interface


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Defines a message inspector object that can be added to the MessageInspectors collection to view or modify messages.

Namespace:   System.ServiceModel.Dispatcher
Assembly:  System.ServiceModel (in System.ServiceModel.dll)

Public Interface IClientMessageInspector

System_CAPS_pubmethodAfterReceiveReply(Message, Object)

Enables inspection or modification of a message after a reply message is received but prior to passing it back to the client application.

System_CAPS_pubmethodBeforeSendRequest(Message, IClientChannel)

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 WCF 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
       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
End Sub

Finally, the following code example shows how to modify the client configuration file to use the endpoint behavior with a particular endpoint.

Universal Windows Platform
Available since 8
.NET Framework
Available since 3.0
Portable Class Library
Supported in: portable .NET platforms
Available since 4.0
Return to top