Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
584 views
in Technique[技术] by (71.8m points)

c# - WCF Service custom message inspector

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...