MessageEncoderFactory Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
An abstract base class that represents the factory for producing message encoders that can read messages from a stream and write them to a stream for various types of message encoding.
public ref class MessageEncoderFactory abstract
public abstract class MessageEncoderFactory
type MessageEncoderFactory = class
Public MustInherit Class MessageEncoderFactory
- Inheritance
-
MessageEncoderFactory
Examples
The following code shows how to write a class that is derived from MessageEncoderFactory:
public override bool IsContentTypeSupported(string contentType)
{
if (base.IsContentTypeSupported(contentType))
{
return true;
}
if (contentType.Length == this.MediaType.Length)
{
return contentType.Equals(this.MediaType, StringComparison.OrdinalIgnoreCase);
}
else
{
if (contentType.StartsWith(this.MediaType, StringComparison.OrdinalIgnoreCase)
&& (contentType[this.MediaType.Length] == ';'))
{
return true;
}
}
return false;
}
public class CustomTextMessageEncoderFactory : MessageEncoderFactory
{
private MessageEncoder encoder;
private MessageVersion version;
private string mediaType;
private string charSet;
internal CustomTextMessageEncoderFactory(string mediaType, string charSet,
MessageVersion version)
{
this.version = version;
this.mediaType = mediaType;
this.charSet = charSet;
this.encoder = new CustomTextMessageEncoder(this);
}
public override MessageEncoder Encoder
{
get
{
return this.encoder;
}
}
public override MessageVersion MessageVersion
{
get
{
return this.version;
}
}
internal string MediaType
{
get
{
return this.mediaType;
}
}
internal string CharSet
{
get
{
return this.charSet;
}
}
}
Remarks
Encoding is the process of transforming a message into a sequence of bytes. Decoding is the reverse process.
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 three abstract base classes:
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. For more information about custom encoders, see Data Transfer and Serialization.
Constructors
MessageEncoderFactory() |
Initializes a new instance of the MessageEncoderFactory class. |
Properties
Encoder |
When overridden in a derived class, gets the message encoder that is produced by the factory. |
MessageVersion |
When overridden in a derived class, gets the message version that is used by the encoders produced by the factory to encode messages. |
Methods
CreateSessionEncoder() |
Returns a message encoder that can be used to correlate messages in session-based exchanges. |
Equals(Object) |
Determines whether the specified object is equal to the current object. (Inherited from Object) |
GetHashCode() |
Serves as the default hash function. (Inherited from Object) |
GetType() |
Gets the Type of the current instance. (Inherited from Object) |
MemberwiseClone() |
Creates a shallow copy of the current Object. (Inherited from Object) |
ToString() |
Returns a string that represents the current object. (Inherited from Object) |
Applies to
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기