WCF肥皂消息删除'到'标题

时间:2012-07-18 19:37:58

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

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

我们正在使用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为假?是否有一个属性设置可以删除所有额外的元素?我处于发布模式。

感谢任何帮助或指示。

1 个答案:

答案 0 :(得分:2)

您使用了错误的messageVersion

要删除,请使用Soap11代替Soap11WSAddressing10

相关问题