The Message class provides a means of communicating arbitrary information between a sender and a receiver on a network. It can be used to relay information, suggest or demand a course of action, or request data.

The structure of a Message object represents a SOAP envelope. It consists of two distinct parts: the message's body and an optional collection of headers, represented by the Headers class. The message content is application-defined data sent from a sender to a receiver. The message headers enable system and application extensibility to meet the changing requirements, because you can define code to manipulate and respond to specific headers. You can also define your own headers. Message headers are serialized or deserialized along with the contents of the message.

Messages are received and sent in particular formats. Support is provided for two formats: the standard text-based XML format and a binary-based XML format. The Message object can be used to represent both SOAP 1.1 and SOAP 1.2 envelopes. Note that an instance of Message is fixed upon creation and is bound to a specific SOAP version. The Version property represents the SOAP version of the message.

A Message object can be serialized to an external store by using the WriteMessage method. Properties of the message can also be serialized, but they have to be individually identified and serialized separately. Deserializing a message to create an in-memory Message object can be done using CreateMessage. Properties must also be deserialized individually and manually added to the property collection for the specific Message instance.

The size of a Message object is fixed to the size of data it is transmitting. Every body is modeled as an instance of XmlReader, with no predefined limit on the size of the stream that the XmlReader instance is wrapping. However, specific channel providers can have a limit on the size of messages that they process.

A Message can be annotated with useful information generated by an entity that has examined and processed the message. This functionality is provided by the Headers and Properties properties. The Headers collection represents the set of SOAP headers on the message.

The Properties property represents the set of processing-level annotations on the message. Because information in headers is transmitted on the wire, an entity that examines a header must support the underlying version(s) of the protocols used by the header. However, properties provide a more version-independent way of annotating a message.

It is recommended that a consumer of a message always call Close when the consumer is finished accessing the contents of the message. This action frees finite system resources (for example, sockets, named pipes) that are tied to the lifetime of the message.

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, suppress the build warning and call SuppressFinalize(Object) and the finalizer itself from (On)(Begin)Close (and/or OnAbort) to emulate what would have been the auto-generated IDisposable behavior.

Notes to Inheritors:

When you inherit from Message, you must override the following members: Headers, and Version.