WCF message body showing <s:Body>... stream ...</s:Body> after modification

Here is solution: if you call Message.ToString() you will get

..stream..

Instead use System.Xml.XmlWriter. Here is a sample:

MessageBuffer buffer = reply.CreateBufferedCopy(Int32.MaxValue);
Message msg = buffer.CreateMessage();
StringBuilder sb = new StringBuilder();
using (System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(sb))
{
    msg.WriteMessage(xw);
    xw.Close();
}
Console.WriteLine("Message Received:\n{0}", sb.ToString());

The problem was that the newMessage body was not shown in the watch window after doing ToString()

Created the buffered copy of the message to be shown in the debugger.

MessageBuffer messageBuffer = newMessage.CreateBufferedCopy(int.MaxValue);
Message message = messageBuffer.CreateMessage();

So there is No problem in the code. It is just that the debugger is not showing the message body as mentioned in the link below

http://msdn.microsoft.com/en-us/library/ms734675(v=VS.90).aspx

in the Accessing the Message Body for Debugging section.

Tags:

Wcf