MessageEncoder Class
Microsoft Silverlight will reach end of support after October 2021. Learn more.
The encoder is the component that is used to write messages to a stream and to read messages from a stream.
Inheritance Hierarchy
System.Object
System.ServiceModel.Channels.MessageEncoder
Namespace: System.ServiceModel.Channels
Assembly: System.ServiceModel (in System.ServiceModel.dll)
Syntax
'Declaration
Public MustInherit Class MessageEncoder
public abstract class MessageEncoder
The MessageEncoder type exposes the following members.
Constructors
Name | Description | |
---|---|---|
MessageEncoder | Initializes a new instance of the MessageEncoder class. |
Top
Properties
Name | Description | |
---|---|---|
ContentType | When overridden in a derived class, gets the MIME content type used by the encoder. | |
MediaType | When overridden in a derived class, gets the media type value that is used by the encoder. | |
MessageVersion | When overridden in a derived class, gets the message version value that is used by the encoder. |
Top
Methods
Name | Description | |
---|---|---|
Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) | |
Finalize | Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.) | |
GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) | |
GetProperty<T> | Returns a typed object requested, if present, from the appropriate layer in the channel stack. | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
IsContentTypeSupported | Returns a value that indicates whether a specified message-level content-type value is supported by the message encoder. | |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | |
ReadMessage(ArraySegment<Byte>, BufferManager) | When overridden in a derived class, reads a message from a specified buffer. | |
ReadMessage(Stream, Int32) | When overridden in a derived class, reads a message from a specified stream. | |
ReadMessage(ArraySegment<Byte>, BufferManager, String) | When overridden in a derived class, reads a message from a specified stream. | |
ReadMessage(Stream, Int32, String) | When overridden in a derived class, reads a message from a specified stream. | |
ToString | Returns the content type that is used by the message encoder. (Overrides Object.ToString().) | |
WriteMessage(Message, Stream) | When overridden in a derived class, writes a message to a specified stream. | |
WriteMessage(Message, Int32, BufferManager) | Writes a message less than a specified size to a byte array buffer. | |
WriteMessage(Message, Int32, BufferManager, Int32) | When overridden in a derived class, writes a message of less than a specified size to a byte array buffer at the specified offset. |
Top
Remarks
MessageEncoder is a base class that provides implementations that support a Multipurpose Internet Mail Extensions (MIME) content type and message version, and defines the interface for the serialization and deserialization of messages according to that content type. Use it as a base class for writing your own custom encoder.
Use this class if you want to implement a custom message encoder. To implement your own custom message encoder, you must provide custom implementations of the following abstract base classes:
MessageEncoder
Override the Encoder to return an instance of your custom MessageEncoder. Then wire up your custom MessageEncoderFactory to the binding element stack used to configure the service or client by overriding the CreateMessageEncoderFactory method to return an instance of this factory.
The task of converting between the in-memory representation of a message and an XML Information Set (Infoset) representation that can be written to a stream is encapsulated within the MessageEncoder class, which most commonly serves as a factory for XML readers and XML writers that support specific types of XML encodings.
The key methods on MessageEncoder are WriteMessage() and ReadMessage(). WriteMessage() takes a Message object and writes it into a Stream object. ReadMessage() takes a Stream object and a maximum header size and returns a Message object.
Examples
The following code shows an example of a class that is derived from MessageEncoder.
Version Information
Silverlight
Supported in: 5, 4, 3
Silverlight for Windows Phone
Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0
XNA Framework
Supported in: Windows Phone OS 7.0
Platforms
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.