title: SOAP Header not understood by .NET client when calling Webservice
body: <p>I've been trying to call a third-party webservice from a .NET client. I have had to set some custom headers for each request in order to adhere to their Authentication requirements.</p>
  
  <p>I have used <a href="https://stackoverflow.com/questions/5836685/correct-way-communicate-wsse-usernametoken-for-soap-webservice">this answer</a> in order for me to get the request header values to appear as so:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"&gt;
     &lt;s:Header&gt;
        &lt;wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" s:mustUnderstand="0"&gt;
           &lt;wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UsernameToken-2"&gt;
              &lt;wsse:Username&gt;Jimbob&lt;/wsse:Username&gt;
              &lt;wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText"&gt;P@ssword&lt;/wsse:Password&gt;
           &lt;/wsse:UsernameToken&gt;
        &lt;/wsse:Security&gt;
     &lt;/s:Header&gt;
     &lt;s:Body&gt;
     ...
     &lt;/s:Body&gt;
  &lt;/s:Envelope&gt;
  </code></pre>
  
  <p>(I am doing this by setting the a custom <code>&lt;endpoint&gt;&lt;headers /&gt;&lt;/endpoint&gt;</code> section in config)</p>
  
  <p>I have inspected the request via Fiddler and it is sending the correct header values, and the webservice is returning expected results.</p>
  
  <p>However, the client is throwing the following exception when it receives the result:</p>
  
  <blockquote>
    <p>System.ServiceModel.ProtocolException : The header 'Security' from the namespace '<a href="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" rel="nofollow noreferrer">http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd</a>' was not understood by the recipient of this message, causing the message to not be processed.  This error typically indicates that the sender of this message has enabled a communication protocol that the receiver cannot process.  Please ensure that the configuration of the client's binding is consistent with the service's binding. </p>
  </blockquote>
  
  <p>The relevant part of the repsonse (from Fiddler) is this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&gt;
     &lt;soap:Header&gt;
        &lt;wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" soap:mustUnderstand="1"&gt;
           &lt;wsse:UsernameToken wsu:Id="UsernameToken-371676"&gt;
              &lt;wsse:Username&gt;SOMEUSERTOKEN&lt;/wsse:Username&gt;
              &lt;wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText"&gt;SOMEUSERTOKEN&lt;/wsse:Password&gt;
           &lt;/wsse:UsernameToken&gt;
        &lt;/wsse:Security&gt;
     &lt;/soap:Header&gt;
     &lt;soap:Body&gt;
     ...
     &lt;soap:Body&gt;
  &lt;/soap:Envelope&gt;
  </code></pre>
  
  <p>Basically I'm now lost. I <em>presume</em> I need to perform some sort of message inspection to flag that header as understood, but it does seem quite a lot of heavy lifting just to interpret a result (which I'm already getting from the webservice).</p>
  
  <p>Any help is much appreciated.</p>