title: PHP Soap Server response formatting
body: <p>I'm making a SOAP web service in PHP that has to fit the requirements of a client's XSD file.</p>
  
  <p>Here is a link to the XSD file, supplied by the client: <a href="http://pastebin.com/MX1BZUXc" rel="nofollow">http://pastebin.com/MX1BZUXc</a></p>
  
  <p>The response they are expecting looks like this:</p>
  
  <p><em>[Some long lines broken for legibility, on the theory that the problem is not whitespace-related.]</em></p>
  
  <pre><code>&lt;s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"&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;CheckVersionResponse xmlns="http://www.---.---/---"&gt;
        &lt;CheckversionResult&gt;
          &lt;ValidationOk&gt;true&lt;/ValidationOk&gt;
          &lt;VersionNumber&gt;1.4.0&lt;/VersionNumber&gt;
          &lt;CurrentRemoteServerTime
            &gt;2014-05-02T09:35:20.368+02:00&lt;/CurrentRemoteServerTime&gt;
        &lt;/CheckversionResult&gt;
      &lt;/CheckVersionResponse&gt;
    &lt;/s:Body&gt;
  &lt;/s:Envelope&gt;
  </code></pre>
  
  <p>However, the response I'm currently getting looks like this:</p>
  
  <pre><code>&lt;env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" 
                xmlns:ns1="http://---.---/" 
                xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                xmlns:enc="http://www.w3.org/2003/05/soap-encoding"&gt;
  &lt;env:Body xmlns:rpc="http://www.w3.org/2003/05/soap-rpc"&gt;
      &lt;ns1:CheckVersionResponse 
        env:encodingStyle="http://www.w3.org/2003/05/soap-encoding"&gt;
          &lt;rpc:result&gt;return&lt;/rpc:result&gt;
          &lt;return xsi:type="enc:Struct"&gt;
              &lt;ValidationOk xsi:type="xsd:int"&gt;1&lt;/ValidationOk&gt;
              &lt;VersionNumber xsi:type="xsd:string"
                &gt;1.4.0&lt;/VersionNumber&gt;
              &lt;CurrentRemoteServerTime xsi:type="xsd:string"
                &gt;2014-05-08T10:31:49&lt;/CurrentRemoteServerTime&gt;
          &lt;/return&gt;
      &lt;/ns1:CheckVersionResponse&gt;
  &lt;/env:Body&gt;
  &lt;/env:Envelope&gt;
  </code></pre>
  
  <p>This is how I made my SOAP webservice:</p>
  
  <pre><code>&lt;?php
  
  /* Helper class for my response object */
  class CheckVersionResult extends stdClass
  {
      /** @var bool */
      public $ValidationOk = '';
      /** @var string */
      public $VersionNumber = '';
      /** @var string */
      public $CurrentRemoteServerTime = '';
  }
  
  /* SOAP interface class */
  class MySoapClass
  {
      /**
       * Returns version
       *
       * @param string $param1
       * @param string $param2
       * @return CheckVersionResult
       */
      public function CheckVersion($param1, $param2)
      {
          $data = new CheckVersionResult();
          $data-&gt;ValidationOk = 1;
          $data-&gt;VersionNumber = '1.4.0';
          $data-&gt;CurrentRemoteServerTime = date('Y-m-d\TH:i:s');
      }
  }
  
  /* Controller class */
  class WebserviceController {
  
      public function indexAction() {
          $soap = new Zend_Soap_Server();
          $soap-&gt;setClass('MySoapClass');
          $soap-&gt;setUri("http://---.---/");
          $mySoapClass = new MySoapClass();
          $soap-&gt;setObject($mySoapClass);
          $soap-&gt;setSoapVersion(SOAP_1_2);
          $soap-&gt;handle();
      }
  
  }
  </code></pre>
  
  <p>And this is how I call my webservice:</p>
  
  <pre><code>$client = new SoapClient(null, array(
      "soap_version" =&gt; SOAP_1_2,
      "location" =&gt; "http://---.---/webservice/index",
      "uri" =&gt; "http://---.---/",
      "trace" =&gt; 1, // enable trace to view what is happening
      "exceptions" =&gt; 0, // disable exceptions
      "cache_wsdl" =&gt; 0)   // no wsdl
  );
  
  $client-&gt;CheckVersion('param1', 'param2');
  header('Content-Type: application/xml; charset=utf-8');
  echo $client-&gt;__getLastResponse();
  die();
  </code></pre>
  
  <p>Does anyone know how I can properly format my SOAP response according to the XSD file I got delivered?</p>