title: How to create PHP SOAP request with multiple namespaces
body: <p>I'm attempting to get a shipping quote from an SOAP service. I've been able to successfully create authentication headers and query the SOAP service with basic requests that require no body parameters. </p>
  
  <p>I'm able to create the proper structure for the request but the namespace values are not showing up in the request output.</p>
  
  <p>Example code:</p>
  
  <pre><code>$client = new SoapClient("http://demo.smc3.com/AdminManager/services/RateWareXL?wsdl",
                     array('trace' =&gt; TRUE));
  
  $headerParams = array('ns1:licenseKey'    =&gt; $key,
                        'ns1:password'      =&gt; $pass,
                        'ns1:username'      =&gt; $user);
  
  $soapStruct = new SoapVar($headerParams, SOAP_ENC_OBJECT);
  $header = new SoapHeader($ns, 'AuthenticationToken', $soapStruct, false);
  $client-&gt;__setSoapHeaders($header);
  
  // Check if shipping is ready - base call
  $ready_to_ship = $client-&gt;isReady();
  </code></pre>
  
  <p>The above works just fine and returns true if the shipping service is available.</p>
  
  <p>So I use the following code to build the request body (only filling required fields):
  I've also tried putting everything into an array and converting that to a SoapVar, I've tried including ns1: and ns2: in the body request creation but that hasn't worked either. I believe something needs to be adjusted in the request creation... not sure of the best approach..</p>
  
  <pre><code>$rate_request = $client-&gt;LTLRateShipment;
  $rate_request-&gt;LTLRateShipmentRequest-&gt;destinationCountry = $destination_country;
  $rate_request-&gt;LTLRateShipmentRequest-&gt;destinationPostalCode = $destination_postal_code;
  $rate_request-&gt;LTLRateShipmentRequest-&gt;destinationPostalCode = $destination_postal_code;
  $rate_request-&gt;LTLRateShipmentRequest-&gt;details-&gt;LTLRequestDetail-&gt;nmfcClass = $ship_class;
  $rate_request-&gt;LTLRateShipmentRequest-&gt;details-&gt;LTLRequestDetail-&gt;weight = $ship_weight;
  $rate_request-&gt;LTLRateShipmentRequest-&gt;originCountry = $origin_country;
  $rate_request-&gt;LTLRateShipmentRequest-&gt;originPostalCode = $origin_postal_code;
  $rate_request-&gt;LTLRateShipmentRequest-&gt;shipmentDateCCYYMMDD = $ship_date; 
  $rate_request-&gt;LTLRateShipmentRequest-&gt;tariffName = $tariff; 
  </code></pre>
  
  <p>And it produces the following XML:</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:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://webservices.smc.com"&gt;
          &lt;SOAP-ENV:Header&gt;
              &lt;ns1:AuthenticationToken&gt;
                  &lt;ns1:licenseKey&gt;xxxxxxxx&lt;/ns1:licenseKey&gt;
                  &lt;ns1:password&gt;xxxxxxxx&lt;/ns1:password&gt;
                  &lt;ns1:username&gt;xxxxxxxxm&lt;/ns1:username&gt;
                      &lt;/ns1:AuthenticationToken&gt;
      &lt;/SOAP-ENV:Header&gt;
      &lt;SOAP-ENV:Body&gt;
          &lt;ns1:LTLRateShipment&gt;
              &lt;LTLRateShipmentRequest&gt;
                  &lt;destinationCountry&gt;USA&lt;/destinationCountry&gt;
                  &lt;destinationPostalCode&gt;10001&lt;/destinationPostalCode&gt;
          &lt;details&gt;
                &lt;LTLRequestDetail&gt;
            &lt;nmfcClass&gt;60&lt;/nmfcClass&gt;
            &lt;weight&gt;300&lt;/weight&gt;
                            &lt;/LTLRequestDetail&gt;
          &lt;/details&gt; 
                            &lt;originCountry&gt;USA&lt;/originCountry&gt;
                  &lt;originPostalCode&gt;90210&lt;/originPostalCode&gt;
                  &lt;shipmentDateCCYYMMDD&gt;20110516&lt;/shipmentDateCCYYMMDD&gt;
                  &lt;tariffName&gt;DEMOLTLA&lt;/tariffName&gt;
              &lt;/LTLRateShipmentRequest&gt;
          &lt;/ns1:LTLRateShipment&gt;
      &lt;/SOAP-ENV:Body&gt;
      &lt;/SOAP-ENV:Envelope&gt;
  </code></pre>
  
  <p>But the output should include the namespaces (web: and web1: where appropriate). The above request returns an error code of missing tariffName. </p>
  
  <p>Here's an example of what the xml request should look like:</p>
  
  <pre><code>    &lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
  xmlns:web="http://webservices.smc.com" xmlns:web1="http://web.ltl.smc.com"&gt; 
     &lt;soapenv:Header&gt; 
        &lt;web:AuthenticationToken&gt; 
           &lt;web:licenseKey&gt; string &lt;/web:licenseKey&gt; 
           &lt;web:password&gt; string &lt;/web:password&gt; 
           &lt;web:username&gt; string &lt;/web:username&gt; 
        &lt;/web:AuthenticationToken&gt; 
     &lt;/soapenv:Header&gt; 
     &lt;soapenv:Body&gt; 
        &lt;web:LTLRateShipment&gt; 
           &lt;web:LTLRateShipmentRequest&gt; 
              &lt;web1:LTL_Surcharge&gt; string &lt;/web1:LTL_Surcharge&gt; 
              &lt;web1:TL_Surcharge&gt; string &lt;/web1:TL_Surcharge&gt; 
              &lt;web1:destinationCity&gt; string &lt;/web1:destinationCity&gt; 
              &lt;web1:destinationCountry&gt; string &lt;/web1:destinationCountry&gt; 
              &lt;web1:destinationPostalCode&gt; string &lt;/web1:destinationPostalCode&gt; 
              &lt;web1:destinationState&gt; string &lt;/web1:destinationState&gt; 
              &lt;web1:details&gt; 
                 &lt;!--Zero or more repetitions:--&gt; 
                 &lt;web1:LTLRequestDetail&gt; 
                    &lt;web1:nmfcClass&gt; string &lt;/web1:nmfcClass&gt; 
                    &lt;web1:weight&gt; string &lt;/web1:weight&gt; 
                 &lt;/web1:LTLRequestDetail&gt; 
              &lt;/web1:details&gt; 
              &lt;web1:discountApplication&gt; string &lt;/web1:discountApplication&gt; 
              &lt;web1:mcDiscount&gt; string &lt;/web1:mcDiscount&gt; 
              &lt;web1:orgDestToGateWayPointFlag&gt; string &lt;/web1:orgDestToGateWayPointFlag&gt; 
              &lt;web1:originCity&gt; string &lt;/web1:originCity&gt; 
              &lt;web1:originCountry&gt; string &lt;/web1:originCountry&gt; 
              &lt;web1:originPostalCode&gt; string &lt;/web1:originPostalCode&gt; 
              &lt;web1:originState&gt; string &lt;/web1:originState&gt; 
              &lt;web1:rateAdjustmentFactor&gt; string &lt;/web1:rateAdjustmentFactor&gt; 
              &lt;web1:shipmentDateCCYYMMDD&gt; string &lt;/web1:shipmentDateCCYYMMDD&gt; 
              &lt;web1:shipmentID&gt; string &lt;/web1:shipmentID&gt; 
              &lt;web1:stopAlternationWeight&gt; string &lt;/web1:stopAlternationWeight&gt; 
              &lt;web1:surchargeApplication&gt; string &lt;/web1:surchargeApplication&gt; 
              &lt;web1:tariffName&gt; string &lt;/web1:tariffName&gt; 
              &lt;web1:weightBreak_Discount_1&gt; string &lt;/web1:weightBreak_Discount_1&gt; 
           &lt;/web:LTLRateShipmentRequest&gt; 
        &lt;/web:LTLRateShipment&gt; 
     &lt;/soapenv:Body&gt; 
  &lt;/soapenv:Envelope&gt;
  </code></pre>
  
  <p>Any suggestions / direction appreciated!</p>