Question

I am currently writing a WCF client for a Java web service that is outside my control. WCF seems to populate the WSA To header with the endpoint address, but this web service requires a different value.

I am currently trying to set the value manually as follows:

var binding = new CustomBinding();
binding.Elements.Add(GetSecurityElement());
binding.Elements.Add
(
    new TextMessageEncodingBindingElement
    (
        MessageVersion.Soap11WSAddressing10,
        Encoding.UTF8
    )
);
binding.Elements.Add(new HttpsTransportBindingElement());

var endpoint = new EndpointAddress
(
    new Uri("endpoint address"),
    new DnsEndpointIdentity("endpoint identity"),
    new AddressHeaderCollection()
);

var client = new Client(binding, endpoint);
client.Open();

using (new OperationContextScope(client.InnerChannel))
{
    OperationContext.Current.OutgoingMessageHeaders.To = new Uri("some other address");
    OperationContext.Current.OutgoingMessageHeaders.MessageId = new UniqueId("message id");
    var response = client.doSomething();
}

Inspecting the request that is generated and sent using Fiddler, I can see that the MessageID header is successfully being set to "message id" rather than the default urn:uuid:[some uuid], but the To header is still being set to "endpoint address" rather than "some other address".

Is there some other way to overwrite the header value?

Was it helpful?

Solution

I have managd to resolve this using the approach oulined here. In code, the solution was to use :

        var endpoint = new EndpointAddress
        (
            new Uri("wsa to address"),
            new DnsEndpointIdentity("endpoint identity"),
            new AddressHeaderCollection()
        );

To set the value of the WSA To header. Then use:

        client.Endpoint.Behaviors.Add(new ClientViaBehavior(new Uri("address")));

To control the address the request is actually sent to.

OTHER TIPS

ClientVia can also be added in the endpointBehavior element in the .config file:

<behaviors>
      <endpointBehaviors>
            <behavior name="someBehavior">
                  <clientVia viaUri="[URL of the actual host]" />
            </behavior>
      </endpointBehaviors>
</behaviors>
<client>
      <endpoint address="[Value of the wsa:To header]" ..... other settings ... />
</client>

Note that you also need to use the correct binding settings - a customBinding with the proper messageVersion in the textMessageEncoding, or wsHttpBinding - in order to use WS-Addressing.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top