Επεξεργασία

Κοινή χρήση μέσω


BodyWriter.CreateBufferedCopy(Int32) Method

Definition

Creates a buffered copy of the body.

public:
 System::ServiceModel::Channels::BodyWriter ^ CreateBufferedCopy(int maxBufferSize);
public System.ServiceModel.Channels.BodyWriter CreateBufferedCopy (int maxBufferSize);
member this.CreateBufferedCopy : int -> System.ServiceModel.Channels.BodyWriter
Public Function CreateBufferedCopy (maxBufferSize As Integer) As BodyWriter

Parameters

maxBufferSize
Int32

The maximum size of the buffer for the body.

Returns

A BodyWriter that contains a copy of this object.

Exceptions

The maxBufferSize is less than zero.

The body has already been written and cannot be written again, or the body writer is not buffered.

Examples

The following sample shows how to create a buffered copy of an existing BodyWriter instance.

string[] strings = { "Hello", "world" };
MyBodyWriter bodyWriter = new MyBodyWriter(strings);

StringBuilder strBuilder = new StringBuilder(10);
XmlWriter writer = XmlWriter.Create(strBuilder);
XmlDictionaryWriter dictionaryWriter = XmlDictionaryWriter.CreateDictionaryWriter(writer);

bodyWriter.WriteBodyContents(dictionaryWriter);
dictionaryWriter.Flush();

MyBodyWriter bufferedBodyWriter = (MyBodyWriter) bodyWriter.CreateBufferedCopy(1024);
Dim strings() As String = {"Hello", "world"}
Dim bodyWriter As New MyBodyWriter(strings)

Dim strBuilder As New StringBuilder(10)
Dim writer As XmlWriter = XmlWriter.Create(strBuilder)
Dim dictionaryWriter As XmlDictionaryWriter = XmlDictionaryWriter.CreateDictionaryWriter(writer)

bodyWriter.WriteBodyContents(dictionaryWriter)
dictionaryWriter.Flush()

Dim bufferedBodyWriter As MyBodyWriter = CType(bodyWriter.CreateBufferedCopy(1024), MyBodyWriter)

Remarks

If IsBuffered is true then the BodyWriter object is returned. If IsBuffered is false then the contents of the BodyWriter up to maxBufferSize is returned. This also calls OnCreateBufferedCopy(Int32) as an extensibility point.

Applies to