【问题标题】:WCF Soap Message Remove 'To' HeaderWCF 肥皂消息删除“到”标题
【发布时间】:2012-07-17 22:31:27
【问题描述】:

虽然关于这个主题还有其他问题,但没有一个真正涵盖这个确切的问题。我很少问问题,因为我通常可以找到答案。

我们正在使用 WCF 客户端与使用 Soap 1.1 的 Java Web 服务通信。我必须创建一个自定义 WseHttpBinding 来添加一个 userNameToken。问题是,当请求被序列化时,会添加一堆 Java 服务讨厌的标头元素。具体如下:

动作 消息ID 回复 到

实际的标题如下所示:

 <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:a="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
 <s:Header>
 <a:Action s:mustUnderstand="1"/>
 <a:MessageID>urn:uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx</a:MessageID>
 <a:ReplyTo><a:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</a:Address></a:ReplyTo>
 <a:To s:mustUnderstand="1">https://xxx.xxx.xxx</a:To>

 <MORE SECURITY ELEMENTS...>
 </s:Header>

在研究了我的选项后,我找不到在不编写自定义编码器或在发送消息之前对其进行操作的情况下删除这些选项的方法。我选择了后者。

使用自定义行为,我使用 IClientMessageInspector 来实现 messageInspector 类。在 BeforeSendRequest 方法中,我使用了以下内容:

message.Headers.RemoveAll("Action", "http://schemas.xmlsoap.org/ws/2004/08/addressing");
message.Headers.RemoveAll("MessageID","http://schemas.xmlsoap.org/ws/2004/08/addressing");
message.Headers.RemoveAll("ReplyTo", "http://schemas.xmlsoap.org/ws/2004/08/addressing");
message.Headers.RemoveAll("To", "http://schemas.xmlsoap.org/ws/2004/08/addressing");

我很惊讶它删除了所有标题异常。结果如下:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:a="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<s:Header>
<a:To s:mustUnderstand="1">https://pilot.eidverifier.com/uru/soap/ut/usv3</a:To>
<MORE SECURITY ELEMENTS...>
</s:Header>

如您所见,“To”元素仍然存在。所以,我的问题是为什么?是否需要发送消息?

我不禁觉得我以错误的方式接近这个问题。有没有办法使 mustUnderstand 错误?是否有删除所有额外元素的属性设置?我处于发布模式。

感谢任何帮助或指导。

【问题讨论】:

标签: .net soap wcf-security wcf-client


【解决方案1】:

你用错了messageVersion

要删除,请使用Soap11 而不是Soap11WSAddressing10

【讨论】:

    【解决方案2】:

    我在使用 WCF Core 时遇到了完全相同的问题

    TextMessageEncodingBindingElement encodingElement = new TextMessageEncodingBindingElement(MessageVersion.Soap12WSAddressing10, System.Text.Encoding.UTF8);
    

    通过切换解决

    MessageVersion msgver = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None);
    TextMessageEncodingBindingElement encodingElement = new TextMessageEncodingBindingElement(msgver, System.Text.Encoding.UTF8);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-20
      • 2017-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多