English 中文(简体)
• 如何从方案角度配置具有约束力的会议,迫使青年联合会发出信息?
原标题:How to programatically configure binding to force JSON encoding of WCF messages?

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编码使用的编码要素,而使用的构造者说这种模式,但“Encoding没有任何选择可选择。

问题回答

网络信息格式由WebHttpBehavior控制。 我很想知道,你是否能够在净吨位上工作。

您无法在网上公布任何财产,以便始终把信息传给初等人物。 原因是,编码要素实际上要看某个头脑的外向信息,如果头部在场,则要向JSON发出这些信息。

了解我所说的话,检查网上职业介绍的执行情况。 通过反射或类似工具进行写作。

因此,你在此有两个选择:

(1) 在你所有即将发出的信息上插入标题,或许使用电线拦截器

(2) 摘录JsonMessageEncodingBledElement(是私人的),改称/重新使用,并将其作为你自己的习俗约束要素。 Voila!

希望会有所帮助。





相关问题
Get DynamicResource Binding in WPF

Can any one help me to get DynamicResource Binding in WPF by code? I have set binding Like follow, TextBlock Background={DynamicResource ColorA} Name="TB" in Xaml. and i need to get the - TB s ...

WPF Binding to specific items in collection

I m currently trying to bind to certain items in a collection in wpf. This is best explained by an example. My XAML is below: <Canvas Name="TaskCanvas" Width="467.667" Height="414"> <...

WPF Dynamic Binding X and Y Co-ordinates

I have a question on WPF dynamic positioning. I want to place Elipses on the screen based on X and Y co-ordinates that i have stored in a collection in C#. I have been made aware of the drawing ...

WPF Data Binding Error in ListBox

I have a ListBox: <ListBox x:Name="HistogramListBox" Grid.Column="1" Margin="8,2,8,0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Template="{StaticResource ...

WCF binding error

So I got into work early today and got the latest from source control. When I try to launch our ASP.NET application, I get this exception: "The binding at system.serviceModel/bindings/wsHttpBinding ...

silverlight 3 collection binding

Someone please help me understand why this binding does not work... I have a class called SelectionManager with a property called dates which is populated by a WCF service. The property is an ...

热门标签