IClientMessageInspector Interface
Collapse the table of content
Expand the table of content

IClientMessageInspector Interface


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 void AfterReceiveReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
  Console.WriteLine("IClientMessageInspector.AfterReceiveReply called.");
  Console.WriteLine("Message: {0}", reply.ToString());

public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, IClientChannel channel)
  Console.WriteLine("IClientMessageInspector.BeforeSendRequest called.");
  return null;

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 void AddBindingParameters(
  ServiceEndpoint endpoint, BindingParameterCollection bindingParameters
) { return; }

public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
  clientRuntime.MessageInspectors.Add(new Inspector());
  foreach (ClientOperation op in clientRuntime.Operations)
    op.ParameterInspectors.Add(new Inspector());

public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
  endpointDispatcher.DispatchRuntime.MessageInspectors.Add(new Inspector());
  foreach (DispatchOperation op in endpointDispatcher.DispatchRuntime.Operations)
    op.ParameterInspectors.Add(new Inspector());

public void Validate(ServiceEndpoint endpoint){ return; }

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 4.5
.NET Framework
Available since 3.0
Portable Class Library
Supported in: portable .NET platforms
Available since 4.0
Return to top
© 2015 Microsoft