MessageBuffer.WriteMessage(Stream) 메서드

정의

이 버퍼의 전체 내용을 지정된 IO 스트림에 씁니다.

public:
 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
Public Overridable Sub WriteMessage (stream As Stream)

매개 변수

stream
Stream

이 버퍼의 전체 내용을 쓸 대상 IO 스트림입니다.

예제

private byte[] ConvertMessageToByteArray(ref Message message)   
{  
    // Memory stream that contains the message.
    var stream = new MemoryStream();  
    // Create an XmlWriter to serialize the message into a byte array.
    var 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.
    message.WriteMessage(writer);  
    // Recreate the message.
    message = buffer.CreateMessage();
    // Flush the contents of the writer so that the stream gets updated.
    writer.Flush();  
    stream.Flush();  
    // Convert the stream to an array.
    byte[] retval = stream.ToArray();
    return retval;
}  

설명

이 함수는 UTF-8 인코더 대신 이진 인코더를 사용합니다. 따라서 직접 변환할 Message수는 없습니다.MessageBuffer 예제 섹션의 코드는 이 문제를 해결하는 방법을 보여 줍니다.

적용 대상