Capture SOAP body from WCF service

Im uses the WCF service and WSDL objects to build the body. I need to capture a melanoma body request / response. I do not need to edit the message, just look in or save / record it.

I tried using the WCF message log as described here: http://msdn.microsoft.com/en-us/library/ms730064.aspx

And using the Microsoft Service Trace Viewer, however, it only shows headers, etc., regardless of the settings I'm using.

They also tried to use a violinist who again seems to ignore the request body.

So ... I need to do something like the one described here: How to get the XML SOAP request for the WCF web service request?

The trace viewer looks good, and I was hoping I could capture the entire message, including the body, using this.

For standard WS services, I used a listener as described here: http://blog.encoresystems.net/articles/how-to-capture-soap-envelopes-when-consuming-a-web-service.aspx

This works exactly the same as I can't and can be turned on / off using app.config

+2
source share
2 answers

I had no problem capturing the entire message using the built-in WCF logging. Did you open the svclog file with your favorite text editor and check that the entire message is missing from XML? Check out the recommended deployment and debugging options in this MSDN article to learn how to log the entire message. In the service trace viewer, make sure you select the Message view and view the entire message in the lower right pane of the Messages or XML tab.

+1
source

There is a much easier way to do this. WCF request and response objects are serialized in XML, so just serialize them into a string - something like this.

var requestXml = SaveAsXmlString(request); 

...

 public static string SaveAsXmlString<T>(T instance) { var sb = new StringBuilder(); using (var writer = new StringWriter(sb)) { var serializer = new XmlSerializer(typeof (T)); serializer.Serialize(writer, instance); } return sb.ToString(); } 

Mike Dennison

0
source

Source: https://habr.com/ru/post/1479089/


All Articles