Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

BodyWriter.CreateBufferedCopy Method

Creates a buffered copy of the body.

Namespace:  System.ServiceModel.Channels
Assemblies:   System.ServiceModel.Primitives (in System.ServiceModel.Primitives.dll)
  System.ServiceModel (in System.ServiceModel.dll)

public BodyWriter CreateBufferedCopy(
	int maxBufferSize


Type: System.Int32

The maximum size of the buffer for the body.

Return Value

Type: System.ServiceModel.Channels.BodyWriter
A BodyWriter that contains a copy of this object.


The maxBufferSize is less than zero.


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

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.

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


MyBodyWriter bufferedBodyWriter = (MyBodyWriter) bodyWriter.CreateBufferedCopy(1024);

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
© 2015 Microsoft