How does WCF Message.ToString() method work?
.net, message, tostring, wcf
Solution
ToString may print the message body, but that's not guaranteed. There are many types of `Message` objects (it's an abstract class). Some of them buffer the whole body, while others only have a forward-only reader over it. The message implementations which buffer the message may write the body when `ToString` is called, and that's what you're seeing. But this is not guaranteed for all message types. In many cases, the body is simply written as "...stream..." when `ToString` is called.
Problem
All of the methods on `System.ServiceModel.Channels.Message` only allow you to read the message body once, and fail with an exception if called after the message has been read. The msdn documentation confirms that it is only possible to read a message body one. However, if you call `ToString()` on an already read message, you appear to get back the entire soap envelope, body and all. So in my case it would seem to be possible to access the body even after it has been read if only the methods would allow it. Is there something I'm missing here? Is using `ToString()` as a work-around to get the body not reliable in some situations? In my case, I'm working on some error logging for some WCF operations and an getting the original message from `OperationContext.RequestContext.RequestMessage`. I'm logging the message with `ToString()` because that is the only way I can find to allow me to log the message body.