Skip to content

Latest commit

 

History

History
44 lines (29 loc) · 2.82 KB

how-to-inspect-and-modify-messages-on-the-service.md

File metadata and controls

44 lines (29 loc) · 2.82 KB
description title ms.date dev_langs ms.assetid
Learn more about: How to: Inspect and Modify Messages on the Service
How to: Inspect and Modify Messages on the Service
03/30/2017
csharp
vb
9c5b1cc7-84f3-45f8-9226-d59c278e8c42

How to: Inspect and Modify Messages on the Service

You can inspect or modify the incoming or outgoing messages across a Windows Communication Foundation (WCF) client by implementing a xref:System.ServiceModel.Dispatcher.IDispatchMessageInspector?displayProperty=nameWithType and inserting it into the service runtime. For more information, see Extending Dispatchers. The equivalent feature on the service is the xref:System.ServiceModel.Dispatcher.IClientMessageInspector?displayProperty=nameWithType.

To inspect or modify messages

  1. Implement the xref:System.ServiceModel.Dispatcher.IDispatchMessageInspector?displayProperty=nameWithType interface.

  2. Implement a xref:System.ServiceModel.Description.IServiceBehavior?displayProperty=nameWithType, xref:System.ServiceModel.Description.IEndpointBehavior?displayProperty=nameWithType, or xref:System.ServiceModel.Description.IContractBehavior?displayProperty=nameWithType interface depending upon the scope at which you want to easily insert your service message inspector.

  3. Insert your behavior prior to calling the xref:System.ServiceModel.ICommunicationObject.Open%2A?displayProperty=nameWithType method on the xref:System.ServiceModel.ServiceHost?displayProperty=nameWithType. For details, see Configuring and Extending the Runtime with Behaviors.

Example

The following code examples show, in order:

  • A service inspector implementation.

  • A service behavior that inserts the inspector.

  • A configuration file that loads and runs the behavior in a service application.

[!code-csharpInterceptors#7] [!code-vbInterceptors#7]

[!code-csharpInterceptors#8] [!code-vbInterceptors#8]

[!code-xmlInterceptors#9]

See also