BodyWriter.CreateBufferedCopy Method (Int32)

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Creates a buffered copy of the body.

Namespace:   System.ServiceModel.Channels
Assembly:  System.ServiceModel (in System.ServiceModel.dll)

public BodyWriter CreateBufferedCopy(
	int maxBufferSize
)

Parameters

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.

Exception Condition
ArgumentOutOfRangeException

The maxBufferSize is less than zero.

InvalidOperationException

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

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

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

Universal Windows Platform
Available since 8
.NET Framework
Available since 3.0
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 4.0
Return to top
Show: