MessageEncoder.WriteMessage MessageEncoder.WriteMessage MessageEncoder.WriteMessage Method

Definition

When overridden in a derived class, writes a message to a specified stream or buffer.

Overloads

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

Parameters

message
Message Message Message

The Message to write to the stream.

stream
Stream Stream Stream

The Stream object to which the message is written.

Examples

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>

Parameters

message
Message Message Message

The Message to write to the message buffer.

maxMessageSize
Int32 Int32 Int32

The maximum message size that can be written.

bufferManager
BufferManager BufferManager BufferManager

The BufferManager that manages the buffer to which the message is written.

Returns

A ArraySegment<T> of type byte that provides the buffer to which the message is serialized.

Remarks

This 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>

Parameters

message
Message Message Message

The Message to write to the message buffer.

maxMessageSize
Int32 Int32 Int32

The maximum message size that can be written.

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.

Returns

A ArraySegment<T> of type byte that provides the buffer to which the message is serialized.

Examples

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;
}

Remarks

This method is called by WriteMessage(Message, Int32, BufferManager, Int32).

Applies to