【问题标题】:The value mtom is not supported in this context for the binding property message绑定属性消息在此上下文中不支持值 mtom
【发布时间】:2021-10-08 13:11:25
【问题描述】:

这是我在将消耗 WCF 服务的 Asp .Net 功能应用程序转换为 .Net 核心时遇到的问题。 WCF 服务期待编码类型为 mtom 的 HTTP 内容,但 .Net 核心不支持它,因此它发出异常, 调用 WCF 服务后,“此上下文中不支持值 mtom 用于绑定属性消息”,

我将在下面附上解决方法

【问题讨论】:

    标签: wcf .net-core binding mtom


    【解决方案1】:

    据我所知,WCF 目前不支持部分 MTOM 功能,所以需要等待。

    【讨论】:

    • wcf 支持 mtom ,是.net core 有问题,所以在回答部分分享一下
    【解决方案2】:

    然后安装 WcfCoreMtomEncoder nuget 包 在为端点创建绑定时的参考文件中, 创建基本HttpBinding

    var transportSecurityBindingElement = new BasicHttpBinding();
    

    设置所需的安全和传输模式

    transportSecurityBindingElement.Security.Mode =BasicHttpSecurityMode.Transport; 
    transportSecurityBindingElement.Security.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.Basic;
    

    创建具有自定义绑定类型的对象

    var customTransportSecurityBinding = new CustomBinding(transportSecurityBindingElement);
    

    使用 mtomMessage 编码器创建编码元素

     var encodingElement = new MtomMessageEncoderBindingElement(new TextMessageEncodingBindingElement());
    

    通过迭代绑定的元素列表查找并替换编码属性

    for (int i = 0; i < customTransportSecurityBinding.Elements.Count; i++)
                    {
                        if (customTransportSecurityBinding.Elements[i] is TextMessageEncodingBindingElement) {
                            customTransportSecurityBinding.Elements[i] = encodingElement;
                            break;
                        }
                    }
    

    返回自定义绑定,以便在任何地方使用它

      return customTransportSecurityBinding
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多