MessageEncoder.WriteMessage MessageEncoder.WriteMessage MessageEncoder.WriteMessage Method

定義

在衍生類別中覆寫時,寫入訊息至指定的資料流或緩衝區中。When overridden in a derived class, writes a message to a specified stream or buffer.

多載

WriteMessage(Message, Stream) WriteMessage(Message, Stream) WriteMessage(Message, Stream)

在衍生類別中覆寫時,寫入訊息至指定的資料流中。When overridden in a derived class, writes a message to a specified stream.

WriteMessage(Message, Int32, BufferManager) WriteMessage(Message, Int32, BufferManager) WriteMessage(Message, Int32, BufferManager)

將小於指定大小的訊息寫入至位元組陣列緩衝區中。Writes a message less than a specified size to a byte array buffer.

WriteMessage(Message, Int32, BufferManager, Int32) WriteMessage(Message, Int32, BufferManager, Int32) WriteMessage(Message, Int32, BufferManager, Int32)

在衍生類別中覆寫時,於位元組陣列緩衝區的指定位移處寫入小於指定大小的訊息。When overridden in a derived class, writes a message of less than a specified size to a byte array buffer at the specified offset.

WriteMessage(Message, Stream) WriteMessage(Message, Stream) WriteMessage(Message, Stream)

在衍生類別中覆寫時,寫入訊息至指定的資料流中。When overridden in a derived class, writes a message to a specified stream.

public:
 abstract void WriteMessage(System::ServiceModel::Channels::Message ^ message, System::IO::Stream ^ stream);
public abstract void WriteMessage (System.ServiceModel.Channels.Message message, System.IO.Stream stream);
abstract member WriteMessage : System.ServiceModel.Channels.Message * System.IO.Stream -> unit

參數

message
Message Message Message

要寫入至 Message 中的 streamThe Message to write to the stream.

stream
Stream Stream Stream

要在其中寫入 Streammessage 物件。The Stream object to which the message is written.

範例

下列程式碼會示範如何實作 WriteMessage(Message, Stream) 方法。The following code shows how to implement the WriteMessage(Message, Stream) method.

public override void WriteMessage(Message message, Stream stream)
{
    XmlWriter writer = XmlWriter.Create(stream, this.writerSettings);
    message.WriteMessage(writer);
    writer.Close();
}

WriteMessage(Message, Int32, BufferManager) WriteMessage(Message, Int32, BufferManager) WriteMessage(Message, Int32, BufferManager)

將小於指定大小的訊息寫入至位元組陣列緩衝區中。Writes a message less than a specified size to a byte array buffer.

public:
 ArraySegment<System::Byte> WriteMessage(System::ServiceModel::Channels::Message ^ message, int maxMessageSize, System::ServiceModel::Channels::BufferManager ^ bufferManager);
public ArraySegment<byte> WriteMessage (System.ServiceModel.Channels.Message message, int maxMessageSize, System.ServiceModel.Channels.BufferManager bufferManager);
member this.WriteMessage : System.ServiceModel.Channels.Message * int * System.ServiceModel.Channels.BufferManager -> ArraySegment<byte>

參數

message
Message Message Message

要寫入至訊息緩衝區的 MessageThe Message to write to the message buffer.

maxMessageSize
Int32 Int32 Int32

可寫入的訊息大小上限。The maximum message size that can be written.

bufferManager
BufferManager BufferManager BufferManager

BufferManager,管理在其中寫入訊息的緩衝區。The BufferManager that manages the buffer to which the message is written.

傳回

ArraySegment<T> 型別的 byte,提供序列化訊息的緩衝區。A ArraySegment<T> of type byte that provides the buffer to which the message is serialized.

備註

這個方法會呼叫 WriteMessage(Message, Int32, BufferManager, Int32) = 0 的抽象方法 messageOffsetThis method calls the abstract method WriteMessage(Message, Int32, BufferManager, Int32) with messageOffset = 0.

WriteMessage(Message, Int32, BufferManager, Int32) WriteMessage(Message, Int32, BufferManager, Int32) WriteMessage(Message, Int32, BufferManager, Int32)

在衍生類別中覆寫時,於位元組陣列緩衝區的指定位移處寫入小於指定大小的訊息。When overridden in a derived class, writes a message of less than a specified size to a byte array buffer at the specified offset.

public:
 abstract ArraySegment<System::Byte> WriteMessage(System::ServiceModel::Channels::Message ^ message, int maxMessageSize, System::ServiceModel::Channels::BufferManager ^ bufferManager, int messageOffset);
public abstract ArraySegment<byte> WriteMessage (System.ServiceModel.Channels.Message message, int maxMessageSize, System.ServiceModel.Channels.BufferManager bufferManager, int messageOffset);
abstract member WriteMessage : System.ServiceModel.Channels.Message * int * System.ServiceModel.Channels.BufferManager * int -> ArraySegment<byte>

參數

message
Message Message Message

要寫入至訊息緩衝區的 MessageThe Message to write to the message buffer.

maxMessageSize
Int32 Int32 Int32

可寫入的訊息大小上限。The maximum message size that can be written.

bufferManager
BufferManager BufferManager BufferManager

BufferManager,管理在其中寫入訊息的緩衝區。The BufferManager that manages the buffer to which the message is written.

messageOffset
Int32 Int32 Int32

從提供緩衝區的位元組陣列開頭開始的區段位移。The offset of the segment that begins from the start of the byte array that provides the buffer.

傳回

ArraySegment<T> 型別的 byte,提供序列化訊息的緩衝區。A ArraySegment<T> of type byte that provides the buffer to which the message is serialized.

範例

下列程式碼會示範如何實作 WriteMessage(Message, Int32, BufferManager, Int32) 方法。The following code shows how to implement the WriteMessage(Message, Int32, BufferManager, Int32) method.

public override ArraySegment<byte> WriteMessage(Message message, int maxMessageSize, BufferManager bufferManager, int messageOffset)
{
    MemoryStream stream = new MemoryStream();
    XmlWriter writer = XmlWriter.Create(stream, this.writerSettings);
    message.WriteMessage(writer);
    writer.Close();
    
    byte[] messageBytes = stream.GetBuffer();
    int messageLength = (int)stream.Position;
    stream.Close();

    int totalLength = messageLength + messageOffset;
    byte[] totalBytes = bufferManager.TakeBuffer(totalLength);
    Array.Copy(messageBytes, 0, totalBytes, messageOffset, messageLength);

    ArraySegment<byte> byteArray = new ArraySegment<byte>(totalBytes, messageOffset, messageLength);
    return byteArray;
}

備註

這個方法是由 WriteMessage(Message, Int32, BufferManager, Int32) 所呼叫。This method is called by WriteMessage(Message, Int32, BufferManager, Int32).

適用於