What xml am I about to send to a service?

In C#, in Visual Studio Debugger, if you are about to send a message to a service but you want to see what you're about to send, do this:

System.Xml.Serialization.XmlSerializer s = new System.Xml.Serialization.XmlSerializer(message.GetType());
s.Serialize(new System.IO.FileStream("c:\\temp\\OutgoingMessage.xml",System.IO.FileMode.Create), message)

Cut and paste it one full command (ie to the semicolon) at a time into the immediate window, and replace message with your actual variable.

Similarly for the return message:

result= serviceProxy.MyServiceMethod(message);
System.Xml.Serialization.XmlSerializer s2 = new System.Xml.Serialization.XmlSerializer(result.GetType());
s2.Serialize(new System.IO.FileStream("c:\\temp\\Result.xml", System.IO.FileMode.Create), result)

It's a quick hack for when you're in the middle of a debugging session - note it doesn't close the file properly - but great for when you've been caught on the hoof. If you do this regularly, you're better off using a developer's proxy like fiddler2 and using that to inspect messages.

What xml am I about to send to a service…

by Chris F Carroll read it in 1 min