I m 创建一种约束性习俗(主要是最初用于诊断目的),即改变方案方式,使世界功能和功能信息得以编码。 在这方面,它想:
public class ConfigurableNetTcpBinding : Binding
{
public enum MessageEncoding
{
Text,
Binary,
MTOM,
ByteStream,
JSON,
};
private TcpTransportBindingElement transport;
private MessageEncodingBindingElement encoding;
public ConfigurableNetTcpBinding(MessageEncoding encoding = MessageEncoding.Binary, bool enableMessageCounters = false)
: base()
{
EnableMessageCounters = enableMessageCounters;
Encoding = encoding;
this.Initialize();
}
public override BindingElementCollection CreateBindingElements()
{
BindingElementCollection elements = new BindingElementCollection();
elements.Add(this.encoding);
elements.Add(this.transport);
return elements;
}
public override string Scheme
{
get { return this.transport.Scheme; }
}
public long MaxReceivedMessageSize
{
get { return transport.MaxReceivedMessageSize; }
set { transport.MaxReceivedMessageSize = value; }
}
public TransferMode TransferMode
{
get { return transport.TransferMode; }
set { transport.TransferMode = value; }
}
public MessageEncoding Encoding { get; private set; }
public bool EnableMessageCounters { get; private set; }
private void Initialize()
{
MessageEncodingBindingElement messageEncoder;
switch (Encoding)
{
default:
case MessageEncoding.Text:
messageEncoder = new TextMessageEncodingBindingElement();
break;
case MessageEncoding.Binary:
messageEncoder = new BinaryMessageEncodingBindingElement();
break;
case MessageEncoding.MTOM:
messageEncoder = new MtomMessageEncodingBindingElement();
break;
case MessageEncoding.ByteStream:
messageEncoder = new ByteStreamMessageEncodingBindingElement();
break;
case MessageEncoding.JSON:
WebMessageEncodingBindingElement webEncoder = new WebMessageEncodingBindingElement();
// Um... what goes here to to configure the webEncoder to serialize with JSON vs POX
messageEncoder = webEncoder;
break;
}
transport = new TcpTransportBindingElement();
encoding = EnableMessageCounters ? new CountingEncoderBindingElement(messageEncoder) : messageEncoder;
}
}
Ignore the CountingEncoderBledElement
... it s only a summaryper forquesting bytes on thetel. 基本上,我试图说明如何召集网络电话会议,以便它总是把信息序列化。 我失踪了什么? All the MSDN Docs/a> 指出,这是供JSON编码使用的编码要素,而使用