MessageEncoderFactory MessageEncoderFactory MessageEncoderFactory MessageEncoderFactory Class

定義

表示用來產生訊息編碼器之處理站的抽象基底類別,該編碼器可從資料流讀取訊息,並將訊息寫入各種訊息編碼類型的資料流中。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
繼承
MessageEncoderFactoryMessageEncoderFactoryMessageEncoderFactoryMessageEncoderFactory

範例

下列程式碼會示範如何撰寫衍生自 MessageEncoderFactory 的類別。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;
        }
    }
}

備註

編碼是將訊息轉換成位元組序列的處理序,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:

覆寫 Encoder,以傳回自訂 MessageEncoder 的執行個體。Override the Encoder to return an instance of your custom MessageEncoder. 然後讓自訂 MessageEncoderFactory 連接用來設定服務或用戶端的繫結項目堆疊,其方式是覆寫 CreateMessageEncoderFactory 方法來傳回此處理站的執行個體。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.

建構函式

MessageEncoderFactory() MessageEncoderFactory() MessageEncoderFactory() MessageEncoderFactory()

初始化 MessageEncoderFactory 類別的新執行個體。Initializes a new instance of the MessageEncoderFactory class.

屬性

Encoder Encoder Encoder Encoder

在衍生類別中覆寫時,會取得此處理站產生的訊息編碼器。When overridden in a derived class, gets the message encoder that is produced by the factory.

MessageVersion MessageVersion MessageVersion MessageVersion

在衍生類別中覆寫時,會取得此處理站所產生之編碼器所用的訊息版本,以編碼訊息。When overridden in a derived class, gets the message version that is used by the encoders produced by the factory to encode messages.

方法

CreateSessionEncoder() CreateSessionEncoder() CreateSessionEncoder() CreateSessionEncoder()

傳回訊息編碼器,它可用來讓工作階段型交換中的訊息相互關聯。Returns a message encoder that can be used to correlate messages in session-based exchanges.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)

適用於