title: PHP SoapClient and a complex header
body: <p>I have been trying for a while now, but I can't figure out how to use PHP SoapCLient in combination with a WSDL to form a complex header (that is, more complex than any tutorial I could find). The envelope that I need to send looks like this:</p>
  
  <pre><code>(001) &lt;?xml version='1.0' encoding='UTF-8'?&gt;
  
  (002) &lt;SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xlink="http://www.w3.org/1999/xlink"&gt;
  
  (003) &lt;SOAP-ENV:Header&gt;
  
  (004) &lt;eb:MessageHeader xmlns:eb="http://www.ebxml.org/namespaces/messageHeader" eb:version="2.0" SOAP-ENV:mustUnderstand="1"&gt;
  
  (005) &lt;eb:From&gt;
  
  (006) &lt;eb:PartyId&gt;webservices.example.com&lt;/eb:PartyId&gt; 
  
  (007) &lt;/eb:From&gt;
  
  (008) &lt;eb:To&gt;
  
  (009) &lt;eb:PartyId&gt;clientURL&lt;/eb:PartyId&gt; 
  
  (010) &lt;/eb:To&gt;
  
  (011) &lt;eb:CPAId&gt;IPCC&lt;/eb:CPAId&gt; 
  
  (012) &lt;eb:ConversationId&gt;ABC123@clientURL.com&lt;/eb:ConversationId&gt; 
  
  (013) &lt;eb:Service eb:type="XML"&gt;Session&lt;/eb:Service&gt; 
  
  (014) &lt;eb:Action&gt;SessionCreateRS&lt;/eb:Action&gt; 
  
  (015) &lt;eb:MessageData&gt;
  
  (016) &lt;eb:MessageId&gt;mid:20030707-12545-1369@webservices.sabre.com&lt;/eb:MessageId&gt; 
  
  (017) &lt;eb:Timestamp&gt;2001-02-15T11:25:12Z&lt;/eb:Timestamp&gt; 
  
  (018) &lt;/eb:MessageData&gt;
  
  (019) &lt;RefToMessageId&gt;mid:20001209-133003-2333@clientURL&lt;/RefToMessageId&gt; 
  
  (020) &lt;/eb:MessageHeader&gt;
  
  (021) &lt;wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/12/secext"&gt;
  
  (022) &lt;wsse:BinarySecurityToken xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/12/utility" wsu:Id="SabreSecurityToken" valueType="String" EncodingType="wsse:Base64Binary"&gt;Shared/IDL:IceSess\/SessMgr:1\.0.IDL/Common/!ICESMS\/RESC!ICESMSLB\/RES.LB!-4954987477210575357!252506!0&lt;/wsse:BinarySecurityToken&gt; 
  
  (023) &lt;/wsse:Security&gt;
  
  (024) &lt;/SOAP-ENV:Header&gt;
  
  (025) &lt;SOAP-ENV:Body&gt;
  
  (026) &lt;eb:Manifest xmlns:eb="http://www.ebxml.org/namespaces/messageHeader" eb:version="2.0"&gt;
  
  (027) &lt;eb:Reference eb:id="SessionCreateRS" xlink:type="simple" xlink:href="cid:SessionCreateRS"
  
  (028) &lt;eb:Description xml:lang="en-US"&gt;Response Message&lt;/eb:Description&gt;"/&gt;
  
  (029) &lt;/eb:Reference&gt;
  
  (030) &lt;/eb:Manifest&gt;
  
  (031) &lt;/SOAP-ENV:Body&gt;
  
  (032) &lt;/SOAP-ENV:Envelope&gt;
  </code></pre>
  
  <p>I tried to make it using __setSoapHeaders() and using SoapVar(). I can't get the right output though. From examples I learned it would be good to use a class to fill the parameters in the XML, so I made an class like this:</p>
  
  <pre><code>class EbXmlMessage{
   public $From = array('PartyId' =&gt; 'www.example.com@example.com');
   public $To = array('PartyId' =&gt; 'example.com');
   public $CPAId = 'XXXX';
   public $ConversationId = '12345@example.com';
   public $Service = 'Session';
   public $Action = 'SessionCreateRQ';
   public $MessageData = array( 'MessageId' =&gt; "mid:12345@example.com",'Timestamp' =&gt; '2010-11-26T08:19:00Z');
  }
  </code></pre>
  
  <p>than I use:</p>
  
  <pre><code>$eb_params = new SoapVar($eb,SOAP_ENC_OBJECT);
  $header =  new SoapHeader($ns,"header", $eb_params,true);
  </code></pre>
  
  <p>But the request does not even slightly begin to look like it has to:</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.opentravel.org/OTA/2002/11" xmlns:ns2="https://cert.webservices.sabre.com/cert"&gt;
   &lt;SOAP-ENV:Header&gt;
    &lt;ns2:header SOAP-ENV:mustUnderstand="1"&gt;
     &lt;From&gt;
      &lt;item&gt;
       &lt;key&gt;PartyId&lt;/key&gt;
       &lt;value&gt;www.example.com@example.com&lt;/value&gt;
      &lt;/item&gt;
     &lt;/From&gt;
     &lt;To&gt;
      &lt;item&gt;
       &lt;key&gt;PartyId&lt;/key&gt;
       &lt;value&gt;webservices.sabre.com&lt;/value&gt;
      &lt;/item&gt;
     &lt;/To&gt;
     &lt;CPAId&gt;XXX&lt;/CPAId&gt;
     &lt;ConversationId&gt;12345@example.com&lt;/ConversationId&gt;
     &lt;Service&gt;Session&lt;/Service&gt;
     &lt;Action&gt;SessionCreateRQ&lt;/Action&gt;
     &lt;MessageData&gt;
      &lt;item&gt;
       &lt;key&gt;MessageId&lt;/key&gt;
       &lt;value&gt;mid:12345@www.example.com&lt;/value&gt;
      &lt;/item&gt;
      &lt;item&gt;
       &lt;key&gt;Timestamp&lt;/key&gt;
       &lt;value&gt;2010-11-26T08:19:00Z&lt;/value&gt;
      &lt;/item&gt;
     &lt;/MessageData&gt;
    &lt;/ns2:header&gt;
   &lt;/SOAP-ENV:Header&gt;
   &lt;SOAP-ENV:Body&gt;
    &lt;ns1:SessionCreateRQ&gt;
     &lt;ns1:POS&gt;
      &lt;ns1:Source PseudoCityCode="XXXX"/&gt;
     &lt;/ns1:POS&gt;
    &lt;/ns1:SessionCreateRQ&gt;
    &lt;param1/&gt;
   &lt;/SOAP-ENV:Body&gt;
  &lt;/SOAP-ENV:Envelope
  </code></pre>
  
  <p>The main problems so far are getting the right tags in the XML on the right place, and I don't know how I can get "eb:" and "wsse:" namespace in the tags. I am hoping to use the SoapClientI() class but I'm not sure if it can handle a more complex XML like the one I need, if not maybe I should use Curl or something similar and just treat the XML as a string? </p>