MessageBuffer.WriteMessage(Stream) MessageBuffer.WriteMessage(Stream) MessageBuffer.WriteMessage(Stream) Method


このバッファーの内容全体を指定した IO ストリームに書き込みます。Writes the entire content of this buffer to the specified IO stream.

 virtual void WriteMessage(System::IO::Stream ^ stream);
public virtual void WriteMessage (System.IO.Stream stream);
abstract member WriteMessage : System.IO.Stream -> unit
override this.WriteMessage : System.IO.Stream -> unit


Stream Stream Stream

このバッファーの内容全体を書き込む IO ストリーム。An IO stream that the entire content of this buffer is written to.

private byte[] ConvertMessageToByteArray(ref Message message)   
....//Memory stream that contains the message  
....MemoryStream stream = new MemoryStream();  
....//Create an XmlWriter to serialize the message into a byte array  
....XmlWriterSettings settings = new XmlWriterSettings();  
....settings.Encoding = System.Text.Encoding.UTF8;  
....XmlWriter writer = XmlWriter.Create(stream, settings);  
....//Copy the message into a buffer   
....//Note: This call changes the original message's state  
....MessageBuffer buffer = message.CreateBufferedCopy(int.MaxValue);  
....//Create a copy of the message  
....message = buffer.CreateMessage();  
....//Serialize the message to the XmlWriter   
....//Recreate the message   
....message = buffer.CreateMessage();  
....//Flush the contents of the writer so that the stream gets updated  
....//Convert the stream to an array  
....byte[] retval = stream.ToArray();  
    return retval;  


この関数は、UTF-8 エンコーダーではなく、バイナリ エンコーダーを使用します。This function uses a binary encoder instead of a UTF-8 encoder. そのため、MessageBuffer から Message に直接変換することはできません。Therefore, you cannot directly convert from a MessageBuffer to a Message. この問題を回避する方法を次のコード例に示します。The code in the example section shows how to work around this problem.