title: PHP - Set a Namespace in SoapClient
body: <p>I'm having issues with a SOAP call, and I believe it is related to a namespace. I'm getting incorrect responses back from the server I'm sending to, and it appears to be thanks to an incorrect SOAP Envelope and namespace.</p>
  
  <pre><code>152     protected function callWithSOAP($xml) {
  153         
  154         try {
  155             $soapClient = new SoapClient($this-&gt;mercuryWSDL, array('trace'=&gt;1));
  156         } catch (Exception $e) {
  157             throw new Exception($e-&gt;getMessage());
  158         }
  159         
  160         $message = array(
  161             'tran'=&gt; $xml,
  162             'pw'=&gt; $this-&gt;mercuryPassword
  163         );      
  164         
  165         // Make SOAP Call
  166         try {
  167             $request = $soapClient-&gt;CreditTransaction($message);
  168         } catch (Exception $e) { 
  169             throw new Exception($e-&gt;getMessage());
  170         }
  171 
  172         $res = $soapClient-&gt;__getLastRequest();
  173         return $res;
  174 
  175         return $request;
  176     }
  </code></pre>
  
  <p>The XML I'm feeding into it in the method signature is fine, I have confirmed that is the same as the server is expecting, its specifically the soap request that is having the problem.</p>
  
  <p>Here is the SOAP request I'm sending with SoapClient:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.mercurypay.com"&gt;
      &lt;SOAP-ENV:Body&gt;
          &lt;ns1:CreditTransaction&gt;
              &lt;ns1:tran&gt;
              &lt;?xml version="1.0"?&gt;
              &lt;TStream&gt;
                  &lt;Transaction&gt;
                      &lt;MerchantID&gt;******&lt;/MerchantID&gt;
                      &lt;TranType&gt;Credit&lt;/TranType&gt;
                      &lt;TranCode&gt;FSASale&lt;/TranCode&gt;
                      &lt;InvoiceNo&gt;12&lt;/InvoiceNo&gt;
                      &lt;RefNo&gt;12&lt;/RefNo&gt;
                      &lt;Account&gt;
                          &lt;AcctNo&gt;*******&lt;/AcctNo&gt;
                          &lt;ExpDate&gt;****&lt;/ExpDate&gt;
                      &lt;/Account&gt;
                      &lt;Amount&gt;
                          &lt;Purchase&gt;25&lt;/Purchase&gt;
                          &lt;FSAPrescription&gt;25&lt;/FSAPrescription&gt;
                      &lt;/Amount&gt;
                  &lt;/Transaction&gt;
              &lt;/TStream&gt;
          &lt;/ns1:tran&gt;
          &lt;ns1:pw&gt;xyz&lt;/ns1:pw&gt;
      &lt;/ns1:CreditTransaction&gt;
  &lt;/SOAP-ENV:Body&gt;
  </code></pre>
  
  <p></p>
  
  <p>But here is what it's actually expecting...how can i match this:
      </p>
  
  <pre><code>&lt;soapenv:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mer="http://www.mercurypay.com" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"&gt;
  &lt;soapenv:Body&gt;
  &lt;mer:CreditTransaction&gt;
  &lt;mer:tran&gt;
  &lt;?xml version="1.0"?&gt;
  &lt;TStream&gt;
    &lt;Transaction&gt;
  &lt;MerchantID&gt;******&lt;/MerchantID&gt;
  &lt;TranType&gt;Credit&lt;/TranType&gt;
  &lt;TranCode&gt;FSASale&lt;/TranCode&gt;
  &lt;InvoiceNo&gt;1&lt;/InvoiceNo&gt;
  &lt;RefNo&gt;1&lt;/RefNo&gt;
  &lt;Account&gt;
    &lt;AcctNo&gt;************&lt;/AcctNo&gt;
    &lt;ExpDate&gt;****&lt;/ExpDate&gt;
  &lt;/Account&gt;
  &lt;Amount&gt;
    &lt;Purchase&gt;63.54&lt;/Purchase&gt;
    &lt;FSAPrescription&gt;63.54&lt;/FSAPrescription&gt;
  &lt;/Amount&gt;
  &lt;/Transaction&gt;
  &lt;/TStream&gt;
  &lt;/mer:tran&gt;
  &lt;mer:pw&gt;xyz&lt;/mer:pw&gt;
  &lt;/mer:CreditTransaction&gt;
  &lt;/soapenv:Body&gt;
  &lt;/soapenv:Envelope&gt;
  </code></pre>
  
  <p>You'll notice the "mer:" all over the place. I believe this is what I need to make get a proper response from the server. Please help me out, this is supposed to go out for testing tomorrow and we just realized that the responses from this are very inconsistant.</p>
  
  <p>Thanks for any help you can provide, I really appreciate it.</p>