title: C# WCF Global Namespaces - Royal Mail
body: <p>I've got a WCF SOAP client which is generating a request. This is being refused by the server as an invalid request. I've traced it down to namespaces using SOAPUI but cannot figure out how I can get the client to produce the required result.</p>
  
  <p>The client was generated as a web service reference from the wsdl and is producing the following SOAP message;</p>
  
  <pre><code>&lt;s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"&gt;
    &lt;s:Header&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;createShipmentRequest xmlns="http://www.royalmailgroup.com/api/ship/V2"&gt;
        &lt;integrationHeader&gt;
          &lt;dateTime xmlns="http://www.royalmailgroup.com/integration/core/V1"&gt;2015-07-23&lt;/dateTime&gt;
          &lt;version xmlns="http://www.royalmailgroup.com/integration/core/V1"&gt;2&lt;/version&gt;
          &lt;identification xmlns="http://www.royalmailgroup.com/integration/core/V1"&gt;
            &lt;applicationId&gt;some random number&lt;/applicationId&gt;
            &lt;transactionId&gt;some reference number&lt;/transactionId&gt;
          &lt;/identification&gt;
        &lt;/integrationHeader&gt;
      &lt;/createShipmentRequest&gt;
    &lt;/s:Body&gt;
  &lt;/s:Envelope&gt;
  </code></pre>
  
  <p>As you can see the namespaces are being outputted on the individual elements...</p>
  
  <p>The working example I have has the namespaces defined in the SOAP Envelope;</p>
  
  <pre><code>&lt;s:Envelope xmlns:v2="http://www.royalmailgroup.com/api/ship/V2" xmlns:v1="http://www.royalmailgroup.com/integration/core/V1" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"&gt;
    &lt;s:Header&gt;&lt;/s:Header&gt;
    &lt;s:Body&gt;
      &lt;v2:createShipmentRequest&gt;
        &lt;v2:integrationHeader&gt;
          &lt;v1:dateTime&gt;2015-07-23&lt;/v1:dateTime&gt;
          &lt;v1:version&gt;2&lt;/v1:version&gt;
          &lt;v1:identification&gt;
            &lt;v1:applicationId&gt;some random number&lt;/v1:applicationId&gt;
            &lt;v1:transactionId&gt;some reference number&lt;/v1:transactionId&gt;
          &lt;/v1:identification&gt;
        &lt;/v2:integrationHeader&gt;
      &lt;/v2:createShipmentRequest&gt;
    &lt;/s:Body&gt;
  &lt;/s:Envelope&gt;
  </code></pre>
  
  <p>From what I understand this should not make a difference but the sever simply rejects the request. After modifying my generated request in SOAPUI it is defiantly this causing the problem, so how can I move the two namespace definitions v1 &amp; v2 to the SOAP Envelope and then have the correct elements use the correct prefix?</p>
  
  <p>My client is initiated using the following function;</p>
  
  <pre><code>private shippingAPIPortTypeClient GetProxy() {
  
    BasicHttpBinding myBinding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
    myBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
  
    shippingClient = new shippingAPIPortTypeClient(myBinding, new EndpointAddress(new Uri(shippingClientSandboxEndpoint), EndpointIdentity.CreateDnsIdentity("api.royalmail.com"), new AddressHeaderCollection()));
    shippingClient.ClientCredentials.ClientCertificate.Certificate = certificate;
  
    return shippingClient;
  }
  </code></pre>