WCF Service custom message inspector

我与影子孤独终老i 提交于 2019-12-29 08:23:06

问题


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);
}

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


回答1:


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:

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

And a good example:

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



来源:https://stackoverflow.com/questions/38532833/wcf-service-custom-message-inspector

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!