BinaryMessageFormatter.Write(Message, Object) 方法

定義

將物件序列化到訊息主體中。Serializes an object into the body of the message.

public:
 virtual void Write(System::Messaging::Message ^ message, System::Object ^ obj);
public void Write (System.Messaging.Message message, object obj);
abstract member Write : System.Messaging.Message * obj -> unit
override this.Write : System.Messaging.Message * obj -> unit
Public Sub Write (message As Message, obj As Object)

參數

message
Message

Message,其 Body 屬性會包含序列化物件。The Message whose Body property will contain the serialized object.

obj
Object

要序列化到訊息本文中的物件。The object to be serialized into the message body.

實作

例外狀況

message 參數為 nullThe message parameter is null.

備註

重要

使用不信任的資料呼叫此方法,會造成安全性上的風險。Calling this method with untrusted data is a security risk. 呼叫此方法時,請一律使用信任的資料。Call this method only with trusted data. 如需詳細資訊,請參閱資料驗證For more information, see Data Validation.

不需要指定最上層物件格式和類型格式來寫入佇列,因為它們必須在讀取時。The top object format and type format need not be specified to write to the queue as they must be when reading. TopObjectFormat TypeFormat 只有在還原序列化訊息時,格式器才會使用和屬性。The TopObjectFormat and TypeFormat properties are used by the formatter only when deserializing a message.

BinaryMessageFormatter可以序列化大部分的物件,但結果不會鬆散結合。The BinaryMessageFormatter can serialize most objects, but the result is not loosely coupled. 不過,它是精簡的,因此格式器對大型物件而言很有效率。However, it is compact, so the formatter is efficient for large objects.

適用於

另請參閱