【问题标题】:C# WCF The SOAP action specified on the message, '"SendEcho"', does not match the action specified on the HttpRequestMessageProperty, 'SendEcho'C# WCF 对消息“SendEcho”指定的 SOAP 操作与 HttpRequestMessageProperty 上指定的操作“SendEcho”不匹配
【发布时间】:2022-01-08 06:40:34
【问题描述】:

标头是通过在方法中实现 IClientMessageInspector 的消息检查器添加的

public object BeforeSendRequest(ref Message request, IClientChannel channel)
            {
                var reqMsgProperty = new HttpRequestMessageProperty();
                reqMsgProperty.Headers.Add("SOAPAction", "SendEcho");
                reqMsgProperty.Headers.Add("Content-Type", "text/xml;charset=UTF-8");
                request.Properties[HttpRequestMessageProperty.Name] = reqMsgProperty;
                //...
                return null;
            }

但它仍然返回这个奇怪的消息:

对消息“SendEcho”指定的 SOAP 操作不匹配 在 HttpRequestMessageProperty 上指定的操作,'SendEcho'。

是否有可能应该以其他方式添加此标头,这样它就不会像字符串一样被双引号包围?如果是那怎么办?

【问题讨论】:

    标签: c# wcf soap azure-functions


    【解决方案1】:

    SOAPAction HTTP 标头是 SOAP 1.1 通信所必需的,但不是 SOAP 1.2 通信所必需的。WCF 遵循此规范,仅在使用 SOAP 1.1 时才包含此标头。
    您使用什么绑定? BasicHttpBinding 使用 SOAP 1.1,但 WSHttpBinding 使用 SOAP 1.2 和 WS-Addressing 1.0。
    您可以阅读: SOAPAction HTTP header field specificationthis thread
    您也可以尝试定义自己的自定义绑定:
    How to add a custom HTTP header to every WCF call?
    Adding Http Header in an existing WCF SOAP Service is not working

    【讨论】:

    • 是的,它是 SOAP 1.1。问题实际上是相反的, reqMsgProperty.Headers.Add("SOAPAction", "SendEcho");缺少双引号 - reqMsgProperty.Headers.Add("SOAPAction", "\"SendEcho\"");它继续前进。这是在 2010 年 6 月 24 日星期四晚上 9:54 在您添加的第二个链接中建议的。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-06
    相关资源
    最近更新 更多