WCF 服务自定义消息检查器

WCF Service custom message inspector(WCF 服务自定义消息检查器)

本文介绍了WCF 服务自定义消息检查器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我构建了一个使用自定义用户名和密码身份验证的 WCF 服务,我正在使用以下代码从客户端应用程序对其进行测试:

I built a WCF Service that uses custom username and password authentication and I am testing it from the client app with the following code:

using (ServiceReferenceClient.TestServiceClient tc = new ServiceReferenceClient.TestServiceClient())
{
    tc.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
    tc.ClientCredentials.UserName.UserName = "User1";
    tc.ClientCredentials.UserName.Password = "Pwd1";
    tc.ServiceMethod(param1, param2, param3);
}

它工作正常,但我需要查看发送到 WCF 服务和响应的实际 SOAP 请求.我怎样才能从我的客户那里做到这一点?

It works fine but I need to see the actual SOAP request sent to the WCF service and response. How can I do that from my client?

我知道我可能需要编写自己的自定义消息检查器,并希望获得一些关于如何构建的指示

I know I might have to write my own custom message inspector and would like some pointers on how to build one

推荐答案

上面评论中提到的选项都适合测试.如果您想要更健壮的东西可以包含在您的代码中,那么我认为您想要实现的是 WCF 消息检查器.

The options mentioned in the comments above are good for testing. If you want something more robust that you can include in your code, then I think what you want to implement is a WCF Message Inspector.

有关如何在客户端执行此操作的更多信息:

More on how to do this on the client:

您可以检查或修改跨域的传入或传出消息WCF 客户端通过实现一个System.ServiceModel.Dispatcher.IClientMessageInspector 和插入它进入客户端运行时.

You can inspect or modify the incoming or outgoing messages across a WCF client by implementing a System.ServiceModel.Dispatcher.IClientMessageInspector and inserting it into the client runtime.

https://msdn.microsoft.com/en-us/library/ms733786(v=vs.110).aspx

还有一个很好的例子:

https://weblogs.asp.net/paolopia/writing-a-wcf-message-inspector

这篇关于WCF 服务自定义消息检查器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:WCF 服务自定义消息检查器

基础教程推荐