2

Im using a WCF service and WSDL objects to build the body. I need to capture the SOAP meassage body request/response. I don't need to edit the message just take a peek or save/log it.

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

And using the Microsoft service trace viewer, this, however, is only showing me the headers etc. regardless of the settings I use.

Have also tried to use fiddler, which again seems to ignore the request body.

So... do I need to do something like what is outlined here: How do I get the XML SOAP request of an WCF Web service request?

The trace viewer looks good & I was hoping I could capture the whole message including the body using this.

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

This works exactly as I wan't and can be switched on/off via the app.config

Community
  • 1
  • 1
baileyswalk
  • 1,198
  • 2
  • 17
  • 29
  • Please show your message logging configuration. It's perfectly possible to get the message contents. Try editing your configuration using the WCF Configuration Editor tool. – John Saunders Mar 22 '12 at 13:52
  • Thanks to you both... just needed to be sure it was possible. Was only running traces on the System.ServiceModel and not the System.ServiceModel.MessageLogging – baileyswalk Mar 22 '12 at 15:40

2 Answers2

1

I haven't had problems capturing the entire message using the WCF built-in message logging. Have you opened the svclog file using your favorite text editor and verified the entire message isn't in XML? Look at the recommended deployment & debugging settings in this MSDN article to see how to log the entire message. In the service trace viewer, make sure you pick the Message view and look for the entire message in the right bottom pane Message or XML tabs.

Sixto Saez
  • 12,610
  • 5
  • 43
  • 51
0

There's a much simpler way to do this. The WCF request and response objects are designed to serialize to XML so just serialize them to 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