我有一个 WCF 服务IDispatchMessageInspector
and a BeforeSendReply
修改消息的 WS-Addressing 标头的方法。这适用于所有标头,但 wsa:To 除外,该标头正在从回复中删除...
public void BeforeSendReply(ref Message reply, object correlationState)
{
reply.Headers.To = new Uri("urn:something:something:something"); // Why won't this show up in the response?
reply.Headers.From = new EndpointAddress("urn:blabla:blabla");
reply.Headers.MessageId = MessageIDHelper.CreateNew();
reply.Headers.ReplyTo = new EndpointAddress(Definitions.WSA_REPLYTO_ANONYMOUS);
reply.Headers.Action = Definitions.WSA_ACTION_SOMETHING_SOMETHING;
}
这导致:
<s:Envelope xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:s="http://www.w3.org/2003/05/soap-envelope">
<s:Header>
<a:Action s:mustUnderstand="1">http://xxx.xx/xxx/Messages/1/Send</a:Action>
<a:RelatesTo>SOME_ID_WHATEVER</a:RelatesTo>
<a:From>
<a:Address>urn:xxx.xx:xxx:xxx</a:Address>
</a:From>
<a:MessageID>urn:uuid:083b5fb7-ff45-4944-b881-b4c590577408</a:MessageID>
<a:ReplyTo>
<a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
</a:ReplyTo>
</s:Header>
...
</s:Envelope>
虽然result.ToString()
(结果=Message
类型)给了我:
<s:Envelope xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:s="http://www.w3.org/2003/05/soap-envelope">
<s:Header>
<a:Action s:mustUnderstand="1">http://xxx.xx/xxx/Messages/1/Send</a:Action>
<a:RelatesTo>SOME_ID_WHATEVER</a:RelatesTo>
<a:To s:mustUnderstand="1">urn:xxx.xx:xxx:xxx<a:To>
<a:From>
<a:Address>urn:xxx.xx:xxx:xxx</a:Address>
</a:From>
<a:MessageID>urn:uuid:083b5fb7-ff45-4944-b881-b4c590577408</a:MessageID>
<a:ReplyTo>
<a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
</a:ReplyTo>
</s:Header>
...
</s:Envelope>
那么...为什么是wsa:To
我的回复中的标题被删除了吗?
的文档TransportBindingElement.ManualAddressing https://msdn.microsoft.com/en-us/library/system.servicemodel.channels.transportbindingelement.manualaddressing(v=vs.110).aspx属性提供了有关寻址行为的一些信息。 IE。如果 ManuelAddressing 的值设置为 false,则发送通道将通道上配置为 To: 收件人的 EndpointAddress 应用于传出消息。这意味着频道对 To: 标头的值有发言权。
现在BeforeSendReply()
在服务级别修改消息内容,然后将其交给通道进行传输。因此,如果 ManuelAddressing 的值为 false,通道将在消息标头中设置自己的 To: 值。
每当 ManuelAddressing 的值设置为 true 时,通道就假定消息已被寻址并且不会添加任何附加信息。
为了将 ManuelAddressing 设置为 True,可以在 web.config 文件中创建自定义绑定:
<customBinding>
<binding name="customBinding_manualAddressingEnabled">
<textMessageEncoding />
<httpTransport manualAddressing="true"/>
</binding>
</customBinding>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)