title: How can I manually override the WSA To header sent by a WCF client
body: <p>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.</p>
  
  <p>I am currently trying to set the value manually as follows:</p>
  
  <pre><code>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();
  }
  </code></pre>
  
  <p>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".</p>
  
  <p>Is there some other way to overwrite the header value?</p>