Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I use the WriteMessage(Stream stream) method of the MessageBuffer object in .NET WCF?
    primarykey
    data
    text
    <p>In trying to figure out how to convert a .NET System.ServiceModel.Channels.Message object into an XmlDocument, I thought I could do this:</p> <pre><code>Message message = Message.CreateMessage(messageVersion, "SOAPAction"); using(var messageBuffer = message.CreateBufferedCopy(int.MaxValue)) { var stream = new MemoryStream(); using(var xmlWriter = XmlWriter.Create(stream)) { var xmlDocument = new XmlDocument(); messageBuffer.WriteMessage(stream); stream.Flush(); stream.Position = 0; xmlDocument.Load(stream); stream.Close(); Debug.Writeline(xmlDocument.OuterXml); } } </code></pre> <p>However, this results in an error on the xmlDocument.Load(stream): </p> <pre><code>"Data at the root level is invalid. Line 1, position 1." </code></pre> <p>I now realize I should be using the WriteMessage of the Message object in conjuction with an XmlWriter object like this:</p> <pre><code>Message message = Message.CreateMessage(messageVersion, "SOAPAction"); using(var messageBuffer = message.CreateBufferedCopy(int.MaxValue)) { var stream = new MemoryStream(); using(var xmlWriter = XmlWriter.Create(stream)) { var xmlDocument = new XmlDocument(); messageBuffer.CreateMessage().WriteMessage(xmlWriter); xmlWriter.Flush(); stream.Flush(); stream.Position = 0; xmlDocument.Load(stream); xmlWriter.Close(); stream.Close(); Debug.WriteLine(xmlDocument.OuterXml); } } </code></pre> <p>I'm sure I'm missing some fundamental point, but this leads me to my question - what use is the WriteMessage(Stream stream) on the MessageBuffer object?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload