1 out of 1 rated this helpful - Rate this topic

MessageBuffer Class

Represents a memory buffer that stores an entire message for future consumption.

System.Object
  System.ServiceModel.Channels.MessageBuffer

Namespace:  System.ServiceModel.Channels
Assembly:  System.ServiceModel (in System.ServiceModel.dll)
public abstract class MessageBuffer : IXPathNavigable, 
	IDisposable

The MessageBuffer type exposes the following members.

  Name Description
Protected method Supported by Portable Class Library MessageBuffer Initializes a new instance of the MessageBuffer class.
Top
  Name Description
Public property Supported by Portable Class Library BufferSize Gets the approximate number of bytes consumed by this MessageBuffer.
Public property Supported by Portable Class Library MessageContentType Gets the type of message content stored in this buffer.
Top
  Name Description
Public method Supported by Portable Class Library Close Finishes working with the buffer.
Public method Supported by Portable Class Library CreateMessage Returns a copy of the original message.
Public method CreateNavigator() Creates a new XPathNavigator object for navigating this object. This method cannot be inherited.
Public method CreateNavigator(Int32) Creates a new XPathNavigator object for navigating this object, with the navigator positioned on the node specified.
Public method CreateNavigator(XmlSpace) Creates a new XPathNavigator object for navigating this object, with the specified xml:space scope.
Public method CreateNavigator(Int32, XmlSpace) Creates a new XPathNavigator object for navigating this object, with the navigator positioned on the specified node and xml:space scope.
Public method Supported by Portable Class Library Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Supported by Portable Class Library Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method Supported by Portable Class Library GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method Supported by Portable Class Library GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method Supported by Portable Class Library MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method Supported by Portable Class Library ToString Returns a string that represents the current object. (Inherited from Object.)
Public method Supported by Portable Class Library WriteMessage Writes the entire content of this buffer to the specified IO stream.
Top
  Name Description
Explicit interface implemetation Private method Supported by Portable Class Library IDisposable.Dispose Releases the unmanaged resources used by the MessageBuffer and optionally releases the managed resources. This method cannot be inherited.
Top

The body of a Message instance can only be consumed or written once. If you wish to consume a Message instance more than once, you should use the MessageBuffer class to completely store an entire Message instance into memory.

A MessageBuffer instance is constructed by calling CreateBufferedCopy of a Message instance. A new MessageBuffer is then created and returned, which assumes ownership of the Message and reads the entire content into memory.

In order to retrieve a copy of a Message from the MessageBuffer, you must call the CreateMessage method of the MessageBuffer. This returns an identical copy of the original Message instance you provided.

You can control the maximum size of the buffer by setting BufferSize to the maximum number of bytes desired. This number does not necessarily cover any transient allocations related to building the buffer, or properties attached to the message.

You should always close a MessageBuffer instance by calling Close when finished working with it. This allows system resources to potentially be freed sooner.

Special note for Managed C++ users deriving from this class:

  • Put your cleanup code in (On)(Begin)Close (and/or OnAbort), not in a destructor.

  • Avoid destructors: they cause the compiler to auto-generate IDisposable

  • Avoid non-reference members: they can cause the compiler to auto-generate IDisposable

  • Avoid finalizers; but if you include one, you should suppress the build warning and call SuppressFinalize(Object) and the finalizer itself from (On)(Begin)Close (and/or OnAbort) in order to emulate what would have been the auto-generated IDisposable behavior.

.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ