MessageBuffer 類別


表示儲存整個訊息以供未來取用的記憶體緩衝區。Represents a memory buffer that stores an entire message for future consumption.

public ref class MessageBuffer abstract : IDisposable
public abstract class MessageBuffer : IDisposable
type MessageBuffer = class
    interface IDisposable
Public MustInherit Class MessageBuffer
Implements IDisposable


Message 執行個體的本文只能取用或寫入一次。The body of a Message instance can only be consumed or written once. 如果希望取用 Message 執行個體超過一次,您應該使用 MessageBuffer 類別,將整個 Message 執行個體完全儲存到記憶體中。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.

呼叫 MessageBuffer 執行個體的 CreateBufferedCopy,即可建構 Message 執行個體。A MessageBuffer instance is constructed by calling CreateBufferedCopy of a Message instance. 然後,系統會建立並傳回新的 MessageBuffer,它會取得 Message 的擁有權,並且將整個內容讀取至記憶體中。A new MessageBuffer is then created and returned, which assumes ownership of the Message and reads the entire content into memory.

為了從 Message 擷取 MessageBuffer 的複本,您必須呼叫 CreateMessageMessageBuffer 方法。In order to retrieve a copy of a Message from the MessageBuffer, you must call the CreateMessage method of the MessageBuffer. 這個方法會傳回所提供之原始 Message 執行個體的相同複本。This returns an identical copy of the original Message instance you provided.

您可以將 BufferSize 設定為所需的位元組數目上限,藉此控制緩衝區的大小上限。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.

使用完畢後,您都要呼叫 MessageBuffer 以關閉 Close 執行個體。You should always close a MessageBuffer instance by calling Close when finished working with it. 這樣可能會更快地釋放系統資源。This allows system resources to potentially be freed sooner.

給衍生自此類別之 Managed C++ 使用者的特別說明:Special note for Managed C++ users deriving from this class:

  • 請將您的清除程式碼置於 (On)(Begin)Close (and/or OnAbort),而不是解構函式。Put your cleanup code in (On)(Begin)Close (and/or OnAbort), not in a destructor.

  • 避免使用解構函式:它們會導致編譯器自動產生 IDisposableAvoid destructors: they cause the compiler to auto-generate IDisposable

  • 避免使用非參考成員:它們會導致編譯器自動產生 IDisposableAvoid non-reference members: they can cause the compiler to auto-generate IDisposable

  • 避免使用完成項;但是假如您加入一個完成項,就應該抑制建置警告並呼叫來自 (On)(Begin)Close (and/or OnAbort) 的 SuppressFinalize(Object) 和完成項,以模擬原本可能自動產生的 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.



初始化 MessageBuffer 類別的新執行個體。Initializes a new instance of the MessageBuffer class.



取得這個 MessageBuffer 取用的大約位元組數目。Gets the approximate number of bytes consumed by this MessageBuffer.


取得這個緩衝區中儲存的訊息內容型別。Gets the type of message content stored in this buffer.



使用緩衝區完畢。Finishes working with the buffer.


傳回原始訊息的複本。Returns a copy of the original message.


建立新的 XPathNavigator 物件,以便巡覽這個物件。Creates a new XPathNavigator object for navigating this object. 這個方法無法被繼承。This method cannot be inherited.


建立新的 XPathNavigator 物件,以便使用位於指定節點的導覽來巡覽這個物件。Creates a new XPathNavigator object for navigating this object, with the navigator positioned on the node specified.

CreateNavigator(Int32, XmlSpace)

建立新的 XPathNavigator 物件,以便使用位於指定節點之導覽與 xml:space 範圍來巡覽這個物件。Creates a new XPathNavigator object for navigating this object, with the navigator positioned on the specified node and xml:space scope.


建立新的 XPathNavigator 物件,以便使用指定的 xml:space 範圍巡覽這個物件。Creates a new XPathNavigator object for navigating this object, with the specified xml:space scope.


判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(繼承來源 Object)

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)

將這個緩衝區的整個內容寫入指定的 IO 資料流。Writes the entire content of this buffer to the specified IO stream.



釋放 MessageBuffer 所使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。Releases the unmanaged resources used by the MessageBuffer and optionally releases the managed resources. 這個方法無法被繼承。This method cannot be inherited.