MessageEncodingBindingElement 클래스

정의

메시지를 인코딩하는 데 사용되는 메시지 버전을 지정하는 바인딩 요소입니다.

public ref class MessageEncodingBindingElement abstract : System::ServiceModel::Channels::BindingElement
public abstract class MessageEncodingBindingElement : System.ServiceModel.Channels.BindingElement
type MessageEncodingBindingElement = class
    inherit BindingElement
Public MustInherit Class MessageEncodingBindingElement
Inherits BindingElement
상속
MessageEncodingBindingElement
파생

예제

다음 코드 예제에서는 파생된 MessageEncodingBindingElement클래스를 구현하는 방법을 보여줍니다.

public class CustomTextMessageBindingElement : MessageEncodingBindingElement, IWsdlExportExtension
{
    private MessageVersion msgVersion;
    private string mediaType;
    private string encoding;
    private XmlDictionaryReaderQuotas readerQuotas;

    CustomTextMessageBindingElement(CustomTextMessageBindingElement binding)
        : this(binding.Encoding, binding.MediaType, binding.MessageVersion)
    {
        this.readerQuotas = new XmlDictionaryReaderQuotas();
        binding.ReaderQuotas.CopyTo(this.readerQuotas);
    }

    public CustomTextMessageBindingElement(string encoding, string mediaType,
        MessageVersion msgVersion)
    {
        if (encoding == null)
            throw new ArgumentNullException(nameof(encoding));

        if (mediaType == null)
            throw new ArgumentNullException(nameof(mediaType));

        if (msgVersion == null)
            throw new ArgumentNullException(nameof(msgVersion));

        this.msgVersion = msgVersion;
        this.mediaType = mediaType;
        this.encoding = encoding;
        this.readerQuotas = new XmlDictionaryReaderQuotas();
    }

    public CustomTextMessageBindingElement(string encoding, string mediaType)
        : this(encoding, mediaType, MessageVersion.Soap11WSAddressing10)
    {
    }

    public CustomTextMessageBindingElement(string encoding)
        : this(encoding, "text/xml")
    {
    }

    public CustomTextMessageBindingElement()
        : this("UTF-8")
    {
    }

    public override MessageVersion MessageVersion
    {
        get
        {
            return this.msgVersion;
        }

        set
        {
            if (value == null)
                throw new ArgumentNullException(nameof(value));
            this.msgVersion = value;
        }
    }

    public string MediaType
    {
        get
        {
            return this.mediaType;
        }

        set
        {
            if (value == null)
                throw new ArgumentNullException(nameof(value));
            this.mediaType = value;
        }
    }

    public string Encoding
    {
        get
        {
            return this.encoding;
        }

        set
        {
            if (value == null)
                throw new ArgumentNullException(nameof(value));
            this.encoding = value;
        }
    }

    // This encoder does not enforces any quotas for the unsecure messages. The
    // quotas are enforced for the secure portions of messages when this encoder
    // is used in a binding that is configured with security.
    public XmlDictionaryReaderQuotas ReaderQuotas
    {
        get
        {
            return this.readerQuotas;
        }
    }

    #region IMessageEncodingBindingElement Members
    public override MessageEncoderFactory CreateMessageEncoderFactory()
    {
        return new CustomTextMessageEncoderFactory(this.MediaType,
            this.Encoding, this.MessageVersion);
    }

    #endregion

    public override BindingElement Clone()
    {
        return new CustomTextMessageBindingElement(this);
    }

    public override IChannelFactory<TChannel> BuildChannelFactory<TChannel>(BindingContext context)
    {
        if (context == null)
            throw new ArgumentNullException(nameof(context));

        context.BindingParameters.Add(this);
        return context.BuildInnerChannelFactory<TChannel>();
    }

    public override bool CanBuildChannelFactory<TChannel>(BindingContext context)
    {
        if (context == null)
            throw new ArgumentNullException(nameof(context));

        return context.CanBuildInnerChannelFactory<TChannel>();
    }

    public override IChannelListener<TChannel> BuildChannelListener<TChannel>(BindingContext context)
    {
        if (context == null)
            throw new ArgumentNullException(nameof(context));

        context.BindingParameters.Add(this);
        return context.BuildInnerChannelListener<TChannel>();
    }

    public override bool CanBuildChannelListener<TChannel>(BindingContext context)
    {
        if (context == null)
            throw new ArgumentNullException(nameof(context));

        context.BindingParameters.Add(this);
        return context.CanBuildInnerChannelListener<TChannel>();
    }

    public override T GetProperty<T>(BindingContext context)
    {
        if (typeof(T) == typeof(XmlDictionaryReaderQuotas))
        {
            return (T)(object)this.readerQuotas;
        }
        else
        {
            return base.GetProperty<T>(context);
        }
    }

    #region IWsdlExportExtension Members

    void IWsdlExportExtension.ExportContract(WsdlExporter exporter, WsdlContractConversionContext context)
    {
    }

    void IWsdlExportExtension.ExportEndpoint(WsdlExporter exporter, WsdlEndpointConversionContext context)
    {
        // The MessageEncodingBindingElement is responsible for ensuring that the WSDL has the correct
        // SOAP version. We can delegate to the WCF implementation of TextMessageEncodingBindingElement for this.
        TextMessageEncodingBindingElement mebe = new TextMessageEncodingBindingElement();
        mebe.MessageVersion = this.msgVersion;
        ((IWsdlExportExtension)mebe).ExportEndpoint(exporter, context);
    }

    #endregion
}

설명

인코딩은 메시지를 바이트 시퀀스로 변형하는 프로세스입니다. 디코딩은 역프로세스입니다. WCF(Windows Communication Foundation)에는 SOAP 메시지에 대한 세 가지 유형의 인코딩인 텍스트, 이진 및 MTOM(메시지 전송 최적화 메커니즘)이 포함됩니다.

사용자 지정 메시지 인코더를 구현하려는 경우 이 클래스를 사용합니다. 사용자 고유의 사용자 지정 메시지 인코더를 구현하려면 다음 세 가지 추상 기본 클래스의 사용자 지정 구현을 제공해야 합니다.

사용자 지정 인스턴스를 Encoder 반환하도록 재정의합니다 MessageEncoder. 이 팩터리의 CreateMessageEncoderFactory 인스턴스를 반환하도록 메서드를 재정의합니다.

파생 MessageEncodingBindingElement 되는 모든 형식은 서비스에 대해 생성된 WSDL 문서에서 SOAP 바인딩의 버전을 업데이트해야 합니다. 이 작업은 생성된 WSDL을 수정하는 메서드를 구현하여 ExportEndpoint(WsdlExporter, WsdlEndpointConversionContext) 수행됩니다.

Windows Communication Foundation(WCF)은 텍스트, 이진 및 MTOM(메시지 전송 최적화 메커니즘) 인코딩을 제공할 수 있는 클래스에서 MessageEncodingBindingElement 파생된 세 가지 유형의 바인딩 요소를 제공합니다.

  • TextMessageEncodingBindingElement: 가장 상호 운용 가능하지만 XML 메시지의 효율성이 가장 낮은 인코더입니다. 웹 서비스 또는 웹 서비스 클라이언트는 일반적으로 텍스트 XML을 이해할 수 있습니다. 그러나 큰 블록의 이진 데이터를 텍스트로 전송하는 것은 효율적이지 않습니다.

  • BinaryMessageEncodingBindingElement: 이진 기반 XML 메시지에 사용되는 문자 인코딩 및 메시지 버전 관리를 지정하는 바인딩 요소를 나타냅니다. 이는 가장 효율적이지만 상호 운용성이 가장 낮은 인코딩 옵션입니다.

  • MtomMessageEncodingBindingElement: MTOM(메시지 전송 최적화 메커니즘) 인코딩을 사용하여 메시지에 사용되는 문자 인코딩 및 메시지 버전 관리를 지정하는 바인딩 요소를 나타냅니다. MTOM은 WCF 메시지의 이진 데이터를 전송하기 위한 효율적인 기술입니다. MTOM 인코더는 효율성과 상호 운용성의 균형을 맞추려고 합니다. MTOM 인코딩은 대부분의 XML을 텍스트 형식으로 전송하지만, 큰 이진 데이터 블록의 경우에는 텍스트로 변환하지 않고 있는 그대로 전송하여 최적화합니다.

생성자

MessageEncodingBindingElement()

MessageEncodingBindingElement 클래스의 새 인스턴스를 초기화합니다.

MessageEncodingBindingElement(MessageEncodingBindingElement)

기존 끝점에서 초기화되는 MessageEncodingBindingElement 클래스의 새 인스턴스를 초기화합니다.

속성

MessageVersion

파생 클래스에서 재정의되는 경우 메시지 인코더 팩터리에서 생성하는 메시지 인코더가 처리할 수 있는 메시지 버전을 가져오거나 설정합니다.

메서드

BuildChannelFactory<TChannel>(BindingContext)

바인딩 컨텍스트를 사용하여 지정된 형식의 채널을 생성하는 채널 팩터리를 초기화합니다.

(다음에서 상속됨 BindingElement)
BuildChannelListener<TChannel>(BindingContext)

바인딩 컨텍스트를 사용하여 지정된 형식의 채널을 수락하기 위해 채널 수신기를 초기화합니다.

(다음에서 상속됨 BindingElement)
CanBuildChannelFactory<TChannel>(BindingContext)

바인딩 요소에서 특정 채널 형식에 대한 채널 팩터리를 만들 수 있는지 여부를 나타내는 값을 반환합니다.

(다음에서 상속됨 BindingElement)
CanBuildChannelListener<TChannel>(BindingContext)

바인딩 요소에서 특정 채널 형식에 대한 수신기를 만들 수 있는지 여부를 나타내는 값을 반환합니다.

(다음에서 상속됨 BindingElement)
Clone()

파생 클래스에서 재정의되는 경우 바인딩 요소 개체의 복사본을 반환합니다.

(다음에서 상속됨 BindingElement)
CreateMessageEncoderFactory()

파생 클래스에서 재정의되는 경우 메시지 인코더를 생성하기 위한 팩터리를 만듭니다.

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetProperty<T>(BindingContext)

요청한 형식화된 개체가 있는 경우 채널 스택의 해당 계층에서 반환합니다.

GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상