title: Manipulating soap evelope in WCF
body: <p>For a project we are connecting to the KVK Handelsregister DataService from the Netherlands. We have setup a WCF client proxy class, however our soap envelope still differs from the envelope they requested, any idea's to solve these 3 problems:</p>
  
  <ol>
  <li>Remove the mustUnderstandAttribute</li>
  <li>The body has no namespace in the elements (ns:)</li>
  <li>The header also does not have the reference to OASIS</li>
  </ol>
  
  <p>Our envelope:</p>
  
  <pre><code>&lt;s:Envelope xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:s="http://www.w3.org/2003/05/soap-envelope"&gt;
    &lt;s:Header&gt;
      &lt;a:Action s:mustUnderstand="1"&gt;http://es.kvk.nl/genereerProduct&lt;/a:Action&gt;
      &lt;a:MessageID&gt;urn:uuid:173035b3-714d-46ef-96c2-1d46962ec897&lt;/a:MessageID&gt;
      &lt;ActivityId CorrelationId="3d2fb1c7-99db-4c88-9745-6cd187281fc6" xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics"&gt;5f48b058-21d5-46c4-8a8b-02f60556ef0e&lt;/ActivityId&gt;
      &lt;a:ReplyTo&gt;
        &lt;a:Address&gt;http://www.w3.org/2005/08/addressing/anonymous&lt;/a:Address&gt;
      &lt;/a:ReplyTo&gt;
      &lt;a:To s:mustUnderstand="1"&gt;http://es.kvk.nl/KVK-DataserviceCT/2012/10&lt;/a:To&gt;
    &lt;/s:Header&gt;
    &lt;s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
      &lt;genereerProduct xmlns="http://schemas.kvk.nl/schemas/hrip/generiekproduct/2013/01"&gt;
        &lt;productRequest&gt;
          &lt;klantreferentie&gt;QW43BA12&lt;/klantreferentie&gt;
          &lt;productnaam&gt;Inschrijving&lt;/productnaam&gt;
          &lt;productsleutel&gt;
            &lt;kvkNummer&gt;01048900&lt;/kvkNummer&gt;
          &lt;/productsleutel&gt;
        &lt;/productRequest&gt;
      &lt;/genereerProduct&gt;
    &lt;/s:Body&gt;
  &lt;/s:Envelope&gt;
  </code></pre>
  
  <p>The envelope as it should be</p>
  
  <pre><code>&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
  xmlns:oas="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" 
  xmlns:ns="http://schemas.kvk.nl/schemas/hrip/generiekproduct/2013/01" 
  xmlns:add="http://www.w3.org/2005/08/addressing"&gt;
              &lt;soapenv:Header&gt;
                          &lt;add:Action&gt;http://es.kvk.nl/genereerProduct&lt;/add:Action&gt;
                          &lt;add:MessageID&gt;uuid://94-b0e0-d4313c898af0&lt;/add:MessageID&gt;
                          &lt;add:To&gt;http://es.kvk.nl/KVK-DataserviceCT/2012/10&lt;/add:To&gt;
              &lt;/soapenv:Header&gt;
              &lt;soapenv:Body&gt;
                          &lt;ns:genereerProduct&gt;
                                      &lt;ns:productRequest&gt;
                                                  &lt;ns:klantreferentie&gt;QW43BA12&lt;/ns:klantreferentie&gt;
                                                  &lt;ns:productnaam&gt;Inschrijving&lt;/ns:productnaam&gt;
                                                  &lt;ns:productsleutel&gt;
                                                              &lt;ns:kvkNummer&gt;01048900&lt;/ns:kvkNummer&gt;
                                                  &lt;/ns:productsleutel&gt;
                                      &lt;/ns:productRequest&gt;
                          &lt;/ns:genereerProduct&gt;
              &lt;/soapenv:Body&gt;
  &lt;/soapenv:Envelope&gt;*
  </code></pre>
  
  <p>As requested below in comments the binding configuration for both the wsHttpBinding and customBinding. Changing this has no influence on the soap envelope, the error with the custom binding is:</p>
  
  <blockquote>
    <p>ERROR An error occurred while receiving the HTTP response to
    <a href="https://webservices" rel="nofollow">https://webservices</a>
    8.kvk.nl/. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context
    being aborted by the  server (possibly due to the service shutting
    down). See server logs for more de tails.</p>
  </blockquote>
  
  <pre><code>&lt;bindings&gt;
    &lt;wsHttpBinding&gt;
      &lt;binding name="ProductServiceSoap11"&gt;
        &lt;security mode="Transport"&gt;
          &lt;message clientCredentialType="Certificate"/&gt;
          &lt;transport clientCredentialType="Certificate" /&gt;
  
        &lt;/security&gt;
      &lt;/binding&gt;
    &lt;/wsHttpBinding&gt;
    &lt;customBinding&gt;
      &lt;binding name="WsHttpSoap11" &gt;
        &lt;transactionFlow /&gt;
        &lt;textMessageEncoding messageVersion="Soap11WSAddressing10"  /&gt;
        &lt;httpsTransport requireClientCertificate="true"  /&gt;
  
      &lt;/binding&gt;
    &lt;/customBinding&gt;
  &lt;/bindings&gt;
  </code></pre>