我引用了这篇 msdn 文章 http://msdn.microsoft.com/en-us/library/aa717047.aspx用于消息检查器。
我面临的问题是 ApplyClientBehavior 没有被调用,因为 AfterReceiveReply 和 BeforeSendRequest 没有被调用。
我引用了以下文章 http://social.msdn.microsoft.com/Forums/en/wcf/thread/707aa031-f4ff-47ab-ba5b-730f7930605e这表示我需要修改客户端 app.config 文件但不确定在可扩展性部分中放置什么。以下没有帮助
<behaviorExtensions>
<add name="Test" type="Client.ServiceReference1.CustomMessageInspectorClient, Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
</behaviorExtensions>
最佳答案
您需要将消息检查器项目的引用添加到您的客户端项目,然后通过代码将行为添加到您的客户端,如下所示:
client.Endpoint.Behaviors.Add(new SchemaValidationBehavior(null, true, true));
按照上面 msdn 文章中的说明下载示例并通过它来使您的示例正常工作会更容易。
关于wcf - ApplyClientBehavior 没有被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8558149/