WCF Soap Message Remove 'To' Header
===

Although there are other questions on this subject, none really cover this exact problem. I rarely ask questions because I can usually find the answer. 

We are using a WCF client to talk to a Java web service that uses Soap 1.1. I had to create a custom WseHttpBinding to add a userNameToken. The problem is that when the request is serialized, a bunch of header elements are added that the Java service hates. These are specifically:

Action
MessageID
ReplyTo
To

The actual header looks like this:<br>

   

     <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:a="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
     <s:Header>
     <a:Action s:mustUnderstand="1"/>
     <a:MessageID>urn:uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx</a:MessageID>
     <a:ReplyTo><a:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</a:Address></a:ReplyTo>
     <a:To s:mustUnderstand="1">https://xxx.xxx.xxx</a:To>
            
     <MORE SECURITY ELEMENTS...>
     </s:Header>


After researching my options, I couldn't find a way to remove those without writing a custom encoder or manipulating the message before it was sent. I chose the latter.

Using a custom behavior, I used the IClientMessageInspector to implement a messageInspector class. In the BeforeSendRequest method, I used the following:

    message.Headers.RemoveAll("Action", "http://schemas.xmlsoap.org/ws/2004/08/addressing");
    message.Headers.RemoveAll("MessageID","http://schemas.xmlsoap.org/ws/2004/08/addressing");
    message.Headers.RemoveAll("ReplyTo", "http://schemas.xmlsoap.org/ws/2004/08/addressing");
    message.Headers.RemoveAll("To", "http://schemas.xmlsoap.org/ws/2004/08/addressing");

I was quite surprised that it removed all of the headers exception for one. Here is the result:

    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:a="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
    <s:Header>
    <a:To s:mustUnderstand="1">https://pilot.eidverifier.com/uru/soap/ut/usv3</a:To>
    <MORE SECURITY ELEMENTS...>
    </s:Header>


As you can see, the 'To' element is still there. So, my question is why? Does it require that to send the message? 

I can't help but feel that I'm approaching this the wrong way. Is there a way to make mustUnderstand false? Is there a property setting that removes all of the extra elements? I'm in release mode.

Any help or direction is appreciated.
