How do I use WS-Addressing in WCF and set the wsa:replyto header?

喜你入骨 提交于 2019-11-29 06:22:09

In order to invoke a service that requires WS-Addressing from WCF you'll have to configure the client endpoint to use a binding that supports it, such as the WSHttpBinding.

You can then set the wsa:ReplyTo header to a specific URL in your client code through the OperationContext.OutgoingMessageHeaders property:

using (new OperationContextScope((IContextChannel)channel))
{
    OperationContext.Current.OutgoingMessageHeaders.ReplyTo =
        new EndpointAddress("http://client/callback");

    channel.DoSomething();
}

In this example we are setting the wsa:ReplyTo header to a known URL where the client channel listens for incoming callback messages from the service.

Alternatively, if the service supports it, you could use the WSDualHttpBinding, which has built in support for duplex communication through WS-Addressing. In this case you would set the callback address through the WSDualHttpBinding.ClientBaseAddress property:

<system.serviceModel>
    <bindings>
        <wsDualHttpBinding>
            <binding clientBaseAddress="http://client/callback" />
        </wsDualHttpBinding>
    </bindings>

    <client>
        <endpoint address="http://server/service"
                  binding="wsDualHttpBinding"
                  contract="Namespace.Service" />
    </client>
</system.serviceModel>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!