title: How is PHP 5.3 SOAP request formed?
body: <p>I am trying to write some code to talk to the SmarterMail API, but I can't seem to make PHP format the request properly. The [ugly] code I have so far is:</p>
  
  <pre><code>&lt;?php
  function array_to_params($in_arr) {
      $out_arr = array();
  
      foreach( $in_arr as $key =&gt; $value ) {
          $out_arr[] = new SoapParam($value, $key);
      }
      return $out_arr;
  }
  
  echo "&lt;pre&gt;";
  
  $soapClient = new SoapClient(
      "http://mailserver.net/Services/svcDomainAdmin.asmx?WSDL",
      array('trace' =&gt; true)
  );
  
  var_dump($soapClient-&gt;__getTypes());die();
  
  $soap_user_params = array(
      'blank'         =&gt; 'blank', //if I don't have a dummy entry the first parameter doesn't show up.
      'AuthUserName'  =&gt; 'admin',
      'AuthPassword'  =&gt; 'derp'
  );
  $soap_user_params = array_to_params($soap_user_params);
  
  $error = FALSE;
  try {
      $info = $soapClient-&gt;__soapCall("GetAllDomains", $soap_user_params);
  //  $info = $soapClient-&gt;GetAllDomains($soap_user_params); //same results
  } catch (SoapFault $fault) {
      $error = TRUE;
      printf("Error %s: %s\n", $fault-&gt;faultcode, $fault-&gt;faultstring);
  }
  
  if( !$error ) {
      var_dump($info);
      echo "\nRequest: " . htmlentities($soapClient-&gt;__getLastRequest());
  }
  
  echo "&lt;/pre&gt;";
  ?&gt;
  </code></pre>
  
  <p>For reference, the WSDL for this function is:</p>
  
  <pre><code>&lt;s:element name="GetAllDomains"&gt;
      &lt;s:complexType&gt;
          &lt;s:sequence&gt;
              &lt;s:element minOccurs="0" maxOccurs="1" name="AuthUserName" type="s:string"/&gt;
              &lt;s:element minOccurs="0" maxOccurs="1" name="AuthPassword" type="s:string"/&gt;
          &lt;/s:sequence&gt;
      &lt;/s:complexType&gt;
  &lt;/s:element&gt;
  </code></pre>
  
  <p>The example request given is:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&gt;
    &lt;soap:Body&gt;
      &lt;GetAllDomains xmlns="http://tempuri.org/"&gt;
        &lt;AuthUserName&gt;string&lt;/AuthUserName&gt;
        &lt;AuthPassword&gt;string&lt;/AuthPassword&gt;
      &lt;/GetAllDomains&gt;
    &lt;/soap:Body&gt;
  &lt;/soap:Envelope&gt;
  </code></pre>
  
  <p>But the request generated by my code is:</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://tempuri.org/"&gt;
      &lt;SOAP-ENV:Body&gt;
          &lt;ns1:GetAllDomains/&gt;
          &lt;AuthUserName&gt;admin&lt;/AuthUserName&gt;
          &lt;AuthPassword&gt;derp&lt;/AuthPassword&gt;
      &lt;/SOAP-ENV:Body&gt;
  &lt;/SOAP-ENV:Envelope&gt;
  </code></pre>
  
  <p>You can see that the username and password parameters are not contained within the GetAllDomains section for some reason. As well, in the code you can see that I have to pass a dummy parameter in first because whatever is first does not show up in the request. Also, I cannot simply pass in an associative array because the keys are not used as parameter names, it puts in 'param1' and 'param2' instead.</p>
  
  <p>I should note that the server accepts the request and spits back a message about the auth failing. There is a built-in SOAP request tester on the server, and when the request fits the given example it works normally.</p>
  
  <p>Everything I've looked up in the PHP docs and through Google seems to indicate that it should not be this difficult. :(</p>
  
  <p>Any help is GREATLY appreciated.</p>
  
  <p>note: I am running PHP 5.3.8 on Apache 2.2 on FreeBSD, built and installed via ports today.</p>
  
  <p><strong>post-answer-edit:</strong></p>
  
  <p>Thanks to Gian's answer below I've gotten this working and greatly simplified the code:</p>
  
  <pre><code>&lt;?php
  
  echo "&lt;pre&gt;";
  
  $soapClient = new SoapClient( "http://mailserver.net/Services/svcDomainAdmin.asmx?WSDL", array( 'trace' =&gt; true ) );
  
  $soap_user_params = array(
      'AuthUserName'  =&gt; 'admin',
      'AuthPassword'  =&gt; 'derp'
  );
  
  try {
      $info = $soapClient-&gt;__soapCall("GetAllDomains", array( 'parameters' =&gt; $soap_user_params ) );
      var_dump($info);
      echo "\nRequest:\n" . htmlentities($soapClient-&gt;__getLastRequest());
  } catch (SoapFault $fault) {
      printf("Error %s: %s\n", $fault-&gt;faultcode, $fault-&gt;faultstring);
  }
  
  echo "&lt;/pre&gt;";
  </code></pre>