Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
371 views
in Technique[技术] by (71.8m points)

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

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.

We are using a contract-first approch with auto-generated code from svcutil (we cannot 'just' change the contract)...

And it's not possible to do in the config file...

I have seen someone 'overriding' some methods to make their own custom header - but this is not a custom header it's a standard in the SOAP protocol.

How can I add the wsa:replyto in the (SOAP) header?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...