gpt4 book ai didi

c# - 为什么wsa是:To header in my reply message removed by WCF?

转载 作者:行者123 更新时间:2023-11-30 17:34:18 25 4
gpt4 key购买 nike

我有一个带有 IDispatchMessageInspectorBeforeSendReply 方法的 WCF 服务,它修改消息的 WS-Addressing header 。这适用于所有 header ,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() (result = 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 header 从我的回复中删除了?

最佳答案

TransportBindingElement.ManualAddressing 的文档属性提供有关寻址行为的一些信息。 IE。如果 ManuelAddressing 的值设置为 false,则发送 channel 将 channel 上配置为 To: addressee 的 EndpointAddress 应用于传出消息。这意味着 channel 对 To: header 的值有发言权。

现在,BeforeSendReply() 在服务级别修改消息的内容,然后将其交给 channel 进行传输。因此,如果 ManuelAddressing 的值为 false, channel 将在消息头中设置自己的 To: 值。

只要 ManuelAddressing 的值设置为 true, channel 就会假定消息已经被寻址并且不会添加任何附加信息。为了将 ManuelAddressing 设置为 True,可以在 web.config 文件中创建自定义绑定(bind):

<customBinding>
<binding name="customBinding_manualAddressingEnabled">
<textMessageEncoding />
<httpTransport manualAddressing="true"/>
</binding>
</customBinding>

关于c# - 为什么wsa是:To header in my reply message removed by WCF?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42701721/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com