如何:检查或修改客户端的消息

通过实现 System.ServiceModel.Dispatcher.IClientMessageInspector 并将其插入客户端运行时,可以检查或修改通过 WCF 客户端的传入或传出消息。有关更多信息,请参见扩展客户端。服务上的等效功能为 System.ServiceModel.Dispatcher.IDispatchMessageInspector

检查或修改消息

  1. 实现 System.ServiceModel.Dispatcher.IClientMessageInspector 接口。

  2. 实现 System.ServiceModel.Description.IEndpointBehaviorSystem.ServiceModel.Description.IContractBehavior,具体取决于您希望轻松插入客户端消息检查器的范围。

  3. System.ServiceModel.ChannelFactory 上调用 System.ServiceModel.ClientBase.OpenSystem.ServiceModel.ICommunicationObject.Open 方法前,插入行为。有关详细信息,请参见使用行为配置和扩展运行时

示例

下面的代码示例按顺序演示以下各项:

  • 客户端检查器实现。
  • 插入检查器的终结点行为。
  • 在客户端应用程序中加载和运行行为的配置文件。

另请参见

参考

System.ServiceModel.Dispatcher.IClientMessageInspector
System.ServiceModel.Dispatcher.IDispatchMessageInspector

概念

使用行为配置和扩展运行时