【问题标题】:WCF CustomBing exception - AddressingNone does not support adding WS-Addressing headersWCF CustomBing 异常 - AddressingNone 不支持添加 WS-Addressing 标头
【发布时间】:2012-08-23 12:07:01
【问题描述】:

当我使用实用创建的 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;
}  

【问题讨论】:

  • 为什么要使用安全对话?删除后是否有效?
  • @LadislavMrnka 不,当我删除它时它也不起作用

标签: c# wcf custom-binding


【解决方案1】:

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

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;
}

【讨论】:

    【解决方案2】:

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

    transport = new HttpsTransportBindingElement
                {
                    MaxBufferPoolSize = 2147483647,
                    MaxBufferSize = 2147483647,
                    MaxReceivedMessageSize = 2147483647,
                    AuthenticationScheme = System.Net.AuthenticationSchemes.Basic
                };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-12
      • 1970-01-01
      • 2013-04-15
      • 1970-01-01
      • 2012-02-26
      • 1970-01-01
      • 2021-12-29
      • 2011-04-26
      相关资源
      最近更新 更多