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

后端 未结 1 1994
一个人的身影
一个人的身影 2020-12-17 19:38

I\'m calling a BizTalk service using WCF. The service requires the wsa:replyto address to be set in the SOAP header to able to make a \'callback\' when the process is done.<

相关标签:
1条回答
  • 2020-12-17 20:32

    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>
    
    0 讨论(0)
提交回复
热议问题