0

当我使用实用创建的 CustomBinding 时,我不断收到以下异常。

寻址版本“AddressingNone (http://schemas.microsoft.com/ws/2005/05/addressing/none)”不支持添加 WS-Addressing 标头。

有没有办法解决这个问题?

private static CustomBinding CreateCustomBinding(bool useHttps)
{
    BindingElement security;
    BindingElement transport;
    if (useHttps)
    {
        security = SecurityBindingElement.CreateSecureConversationBindingElement(
            SecurityBindingElement.CreateUserNameOverTransportBindingElement());
        transport = new HttpsTransportBindingElement
        {
            MaxBufferPoolSize = 2147483647,
            MaxBufferSize = 2147483647,
            MaxReceivedMessageSize = 2147483647,
        };
    }
    else
    {
        security = SecurityBindingElement.CreateSecureConversationBindingElement(
            SecurityBindingElement.CreateUserNameForSslBindingElement(true));
        transport = new HttpTransportBindingElement
        {
            MaxBufferPoolSize = 2147483647,
            MaxBufferSize = 2147483647,
            MaxReceivedMessageSize = 2147483647,
        };
    }


    var encoding = new MtomMessageEncodingBindingElement
    {
        MaxReadPoolSize = 64,
        MaxWritePoolSize = 16,
        MaxBufferSize = 2147483647,
        MessageVersion = MessageVersion.Soap11,
        WriteEncoding = System.Text.Encoding.UTF8
    };

    //var encoding = new TextMessageEncodingBindingElement();


    var customBinding = new CustomBinding();

    customBinding.Elements.Add(security);
    customBinding.Elements.Add(encoding);
    customBinding.Elements.Add(transport);

    return customBinding;
}  
4

2 回答 2

3

以防万一有人感兴趣,下面是我的解决方案。我添加了一个if用于处理文本编码部分并更新了SecurityBindingElement以下内容if (useHttps)

private static CustomBinding CreateCustomBinding(bool useHttps, bool textEncoding)
{
    BindingElement security;
    BindingElement encoding;
    BindingElement transport;
    if (useHttps)
    {
        var seq = SecurityBindingElement.CreateUserNameOverTransportBindingElement();
        seq.MessageSecurityVersion =
            MessageSecurityVersion.
                WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10;
        seq.SecurityHeaderLayout = SecurityHeaderLayout.Lax;
        seq.DefaultAlgorithmSuite = SecurityAlgorithmSuite.Default;

        security = seq;
        transport = new HttpsTransportBindingElement
        {
            MaxBufferPoolSize = 2147483647,
            MaxBufferSize = 2147483647,
            MaxReceivedMessageSize = 2147483647,
        };
    }
    else
    {
        security = SecurityBindingElement.CreateUserNameOverTransportBindingElement();
        transport = new HttpTransportBindingElement
        {
            MaxBufferPoolSize = 2147483647,
            MaxBufferSize = 2147483647,
            MaxReceivedMessageSize = 2147483647,
        };
    }

    if (textEncoding)
        encoding = new TextMessageEncodingBindingElement
        {
            MaxReadPoolSize = 64,
            MaxWritePoolSize = 16,
            MessageVersion = MessageVersion.Soap11,
            WriteEncoding = System.Text.Encoding.UTF8
        };
    else
        encoding = new MtomMessageEncodingBindingElement
        {
            MaxReadPoolSize = 64,
            MaxWritePoolSize = 16,
            MaxBufferSize = 2147483647,
            MessageVersion = MessageVersion.Soap11,
            WriteEncoding = System.Text.Encoding.UTF8
        };

    var customBinding = new CustomBinding();

    customBinding.Elements.Add(security);
    customBinding.Elements.Add(encoding);
    customBinding.Elements.Add(transport);

    return customBinding;
}
于 2012-08-25T00:19:03.227 回答
0

它对我有用,只需进行一些小改动。谢谢塔瓦尼。只是我为 HTTPSTransportBinidingElement 将 AuthenticationSheme 设置为 Basic。

transport = new HttpsTransportBindingElement
            {
                MaxBufferPoolSize = 2147483647,
                MaxBufferSize = 2147483647,
                MaxReceivedMessageSize = 2147483647,
                AuthenticationScheme = System.Net.AuthenticationSchemes.Basic
            };
于 2014-09-03T20:35:17.720 回答