Export (0) Print
Expand All

Message Class

Represents the unit of communication between endpoints in a distributed environment.

System.Object
  System.ServiceModel.Channels.Message

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

[<AbstractClass>]
type Message =  
    class 
        interface IDisposable 
    end

The Message type exposes the following members.

  NameDescription
Protected methodSupported by Portable Class LibraryMessageInitializes a new instance of the Message class.
Top

  NameDescription
Public propertySupported by Portable Class LibraryHeadersWhen overridden in a derived class, gets the headers of the message.
Protected propertySupported by Portable Class LibraryIsDisposedReturns a value that indicates whether the Message is disposed.
Public propertySupported by Portable Class LibraryIsEmptyReturns a value that indicates whether the Message is empty.
Public propertySupported by Portable Class LibraryIsFaultGets a value that indicates whether this message generates any SOAP faults.
Public propertySupported by Portable Class LibraryPropertiesWhen overridden in a derived class, gets a set of processing-level annotations to the message.
Public propertySupported by Portable Class LibraryStateGets the current state of this Message.
Public propertySupported by Portable Class LibraryVersionWhen overridden in a derived class, gets the SOAP version of the message.
Top

  NameDescription
Public methodBeginWriteBodyContentsStarts the asynchronous writing of the contents of the message body.
Public methodBeginWriteMessageStarts the asynchronous writing of the entire message.
Public methodSupported by Portable Class LibraryCloseCloses the Message and releases any resources.
Public methodCreateBufferedCopyStores an entire Message into a memory buffer for future access.
Public methodStatic memberSupported by Portable Class LibraryCreateMessage(MessageVersion, String)Creates a message that contains a version and an action.
Public methodStatic memberCreateMessage(MessageVersion, MessageFault, String)Creates a message that contains a SOAP fault, a version and an action.
Public methodStatic memberSupported by Portable Class LibraryCreateMessage(MessageVersion, String, Object)Creates a message with the specified version, action and body.
Public methodStatic memberSupported by Portable Class LibraryCreateMessage(MessageVersion, String, BodyWriter)Creates a message with a body that consists of an array of bytes.
Public methodStatic memberSupported by Portable Class LibraryCreateMessage(MessageVersion, String, XmlDictionaryReader)Creates a message with the specified version, action and body.
Public methodStatic memberSupported by Portable Class LibraryCreateMessage(MessageVersion, String, XmlReader)Creates a message using the specified reader, action and version.
Public methodStatic memberCreateMessage(XmlDictionaryReader, Int32, MessageVersion)Creates a message using the specified reader, action and version.
Public methodStatic memberCreateMessage(XmlReader, Int32, MessageVersion)Creates a message using the specified reader, action and version.
Public methodStatic memberCreateMessage(MessageVersion, FaultCode, String, String)Creates a message that contains a SOAP fault, the reason for the fault, a version and an action.
Public methodStatic memberSupported by Portable Class LibraryCreateMessage(MessageVersion, String, Object, XmlObjectSerializer)Creates a message using the specified version, action, message body and serializer.
Public methodStatic memberCreateMessage(MessageVersion, FaultCode, String, Object, String)Creates a message that contains a SOAP fault, a reason and the detail for the fault, a version and an action.
Public methodEndWriteBodyContentsEnds the asynchronous writing of the contents of the message body.
Public methodEndWriteMessageEnds the asynchronous writing of the entire message.
Public methodSupported by Portable Class LibraryEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodSupported by Portable Class LibraryFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by Portable Class LibraryGetBody(T)()Retrieves the body of this Message instance.
Public methodSupported by Portable Class LibraryGetBody(T)(XmlObjectSerializer)Retrieves the body of this Message using the specified serializer.
Public methodSupported by Portable Class LibraryGetBodyAttributeRetrieves the attributes of the message body.
Public methodSupported by Portable Class LibraryGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodSupported by Portable Class LibraryGetReaderAtBodyContentsGets the XML dictionary reader that accesses the body content of this message.
Public methodSupported by Portable Class LibraryGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodSupported by Portable Class LibraryMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Protected methodOnBeginWriteBodyContentsRaises an event when the message starts writing the contents of the message body.
Protected methodOnBeginWriteMessageRaises an event the writing of entire messages starts.
Protected methodSupported by Portable Class LibraryOnBodyToStringCalled when the message body is converted to a string.
Protected methodSupported by Portable Class LibraryOnCloseCalled when the message is closing.
Protected methodOnCreateBufferedCopyCalled when a message buffer is created to store this message.
Protected methodOnEndWriteBodyContentsRaises an event when writing of the contents of the message body ends.
Protected methodOnEndWriteMessageRaises an event when the writing of the entire message ends.
Protected methodOnGetBody(T)Called when the body of the message is retrieved.
Protected methodSupported by Portable Class LibraryOnGetBodyAttributeCalled when the attributes of the message body is retrieved.
Protected methodSupported by Portable Class LibraryOnGetReaderAtBodyContentsCalled when an XML dictionary reader that accesses the body content of this message is retrieved.
Protected methodSupported by Portable Class LibraryOnWriteBodyContentsCalled when the message body is written to an XML file.
Protected methodSupported by Portable Class LibraryOnWriteMessageCalled when the entire message is written to an XML file.
Protected methodSupported by Portable Class LibraryOnWriteStartBodyCalled when the start body is written to an XML file.
Protected methodSupported by Portable Class LibraryOnWriteStartEnvelopeCalled when the start envelope is written to an XML file.
Protected methodSupported by Portable Class LibraryOnWriteStartHeadersCalled when the start header is written to an XML file.
Public methodSupported by Portable Class LibraryToStringReturns a string that represents the current Message instance. (Overrides Object.ToString().)
Public methodSupported by Portable Class LibraryWriteBody(XmlDictionaryWriter)Writes the body element using the specified XmlDictionaryWriter.
Public methodSupported by Portable Class LibraryWriteBody(XmlWriter)Serializes the message body using the specified XmlWriter.
Public methodSupported by Portable Class LibraryWriteBodyContentsSerializes the body content using the specified XmlDictionaryWriter.
Public methodSupported by Portable Class LibraryWriteMessage(XmlDictionaryWriter)Serializes the entire message using the specified XmlDictionaryWriter.
Public methodSupported by Portable Class LibraryWriteMessage(XmlWriter)Serializes the entire message using the specified XmlWriter.
Public methodSupported by Portable Class LibraryWriteStartBody(XmlDictionaryWriter)Serializes the start body of the message using the specified XmlDictionaryWriter.
Public methodSupported by Portable Class LibraryWriteStartBody(XmlWriter)Serializes the start body of the message using the specified XmlDictionaryWriter.
Public methodSupported by Portable Class LibraryWriteStartEnvelopeSerializes the start envelope using the specified XmlDictionaryWriter.
Top

  NameDescription
Public Extension MethodToHttpRequestMessage Creates a HttpRequestMessage instance from an Message instance. (Defined by MessageExtensionMethods.)
Public Extension MethodToHttpResponseMessage Creates a HttpResponseMessage instance from an Message instance. (Defined by MessageExtensionMethods.)
Top

  NameDescription
Explicit interface implemetationPrivate methodSupported by Portable Class LibraryIDisposable.DisposeCloses all the resources used by this message. This method cannot be inherited.
Top

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.

To create a Message instance, use one of the CreateMessage methods.

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.

The following code example shows a client that uses the channel factory to send a message and read the reply.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2015 Microsoft