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 |
|
9c5b1cc7-84f3-45f8-9226-d59c278e8c42 |
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.
-
Implement the xref:System.ServiceModel.Dispatcher.IDispatchMessageInspector?displayProperty=nameWithType interface.
-
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.
-
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.
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]
- xref:System.ServiceModel.Dispatcher.IClientMessageInspector?displayProperty=nameWithType
- xref:System.ServiceModel.Dispatcher.IDispatchMessageInspector?displayProperty=nameWithType
- Configuring and Extending the Runtime with Behaviors