title: ws-security and nusoap not working
body: <p>for a project I need to contact another companies webservice. They have made it on Soap, and it's all detailed etc. I found out the variables and types and what method etc.</p>
  
  <p>They also stated that I should use WS-security with pwd and username in the headers.</p>
  
  <p>So I made this with nusoap:</p>
  
  <pre><code>require_once('../lib/nusoap.php');
  $client = new nusoap_client("http://webservice.client.com/cir.asmx?WSDL", 'wsdl');
  $err = $client-&gt;getError();
  if ($err) {
      echo '&lt;h2&gt;Constructor error&lt;/h2&gt;&lt;pre&gt;' . $err . '&lt;/pre&gt;';
  }
  $client-&gt;soap_defencoding = 'UTF-8';
  
  $result = $client-&gt;call('GetLastUpdate');
  // Check for a fault
  if ($client-&gt;fault) {
      echo '&lt;h2&gt;Fault&lt;/h2&gt;&lt;pre&gt;';
      print_r($result);
      echo '&lt;/pre&gt;';
  } else {
      // Check for errors
      $err = $client-&gt;getError();
      if ($err) {
          // Display the error
          echo '&lt;h2&gt;Error&lt;/h2&gt;&lt;pre&gt;' . $err . '&lt;/pre&gt;';
      } else {
          // Display the result
          echo '&lt;h2&gt;Result&lt;/h2&gt;&lt;pre&gt;';
          print_r($result);
          echo '&lt;/pre&gt;';
      }
  }
  echo '&lt;h2&gt;Request&lt;/h2&gt;&lt;pre&gt;' . htmlspecialchars($client-&gt;request, ENT_QUOTES) . '&lt;/pre&gt;';
  echo '&lt;h2&gt;Response&lt;/h2&gt;&lt;pre&gt;' . htmlspecialchars($client-&gt;response, ENT_QUOTES) . '&lt;/pre&gt;';
  echo '&lt;h2&gt;Debug&lt;/h2&gt;&lt;pre&gt;' . htmlspecialchars($client-&gt;debug_str, ENT_QUOTES) . '&lt;/pre&gt;';
  </code></pre>
  
  <p>then I added:</p>
  
  <pre><code>$client-&gt;setCredentials('******','*******','basic');
  </code></pre>
  
  <p>which didn't work, so I looked up the ws-security style and added the following instead:</p>
  
  <pre><code>$auth='&lt;wsse:Security SOAP-ENV:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"&gt;
  &lt;wsse:UsernameToken&gt;
      &lt;wsse:Username&gt;********&lt;/wsse:Username&gt;
      &lt;wsse:Password Type="wsse:PasswordText"&gt;*******&lt;/wsse:Password&gt;
      &lt;wsse:Nonce&gt;'.base64_encode(pack('H*',$nonce)).'&lt;/wsse:Nonce&gt;
      &lt;wsu:Created xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"&gt;'.time().'&lt;/wsu:Created&gt;
     &lt;/wsse:UsernameToken&gt;
  &lt;/wsse:Security&gt;';
  
  $client-&gt;setHeaders($auth);
  </code></pre>
  
  <p>Which didn't work either...they give the same error....this is what it returns:</p>
  
  <pre><code>Fault
  
  Array
  (
      [faultcode] =&gt; q0:Security
      [faultstring] =&gt; Header http://schemas.xmlsoap.org/ws/2004/08/addressing:Action for ultimate recipient is required but not present in the message.
      [faultactor] =&gt; http://webservice.client.com/cir.asmx
  )
  Request
  
  POST /cir.asmx HTTP/1.0
  Host: webservice.client.com
  User-Agent: NuSOAP/0.9.5 (1.123)
  Content-Type: text/xml; charset=UTF-8
  SOAPAction: "http://www.client.com/namespaces/cir01/GetLastUpdate"
  Content-Length: 967
  
  &lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns2278="http://tempuri.org"&gt;&lt;SOAP-ENV:Header&gt;&lt;wsse:Security SOAP-ENV:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"&gt;
  &lt;wsse:UsernameToken&gt;
      &lt;wsse:Username&gt;*******&lt;/wsse:Username&gt;
      &lt;wsse:Password Type="wsse:PasswordText"&gt;********&lt;/wsse:Password&gt;
      &lt;wsse:Nonce&gt;&lt;/wsse:Nonce&gt;
      &lt;wsu:Created xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"&gt;1300862463&lt;/wsu:Created&gt;
     &lt;/wsse:UsernameToken&gt;
  &lt;/wsse:Security&gt;&lt;/SOAP-ENV:Header&gt;&lt;SOAP-ENV:Body&gt;&lt;GetLastUpdate xmlns="http://www.client.com/namespaces/cir01"&gt;&lt;/GetLastUpdate&gt;&lt;/SOAP-ENV:Body&gt;&lt;/SOAP-ENV:Envelope&gt;
  Response
  
  HTTP/1.1 500 Internal Server Error
  Connection: close
  Date: Wed, 23 Mar 2011 06:39:57 GMT
  Server: Microsoft-IIS/6.0
  X-Powered-By: ASP.NET
  X-AspNet-Version: 2.0.50727
  Cache-Control: private
  Content-Type: text/xml; charset=utf-8
  Content-Length: 1421
  
  &lt;?xml version="1.0" encoding="utf-8"?&gt;&lt;soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"&gt;&lt;soap:Header&gt;&lt;wsa:Action&gt;http://schemas.xmlsoap.org/ws/2004/08/addressing/fault&lt;/wsa:Action&gt;&lt;wsa:MessageID&gt;urn:uuid:b8c93511-b6e6-4247-9ab5-65bd4a6aa286&lt;/wsa:MessageID&gt;&lt;wsa:RelatesTo&gt;urn:uuid:6dfa917b-3163-4ae9-bd84-0855b7a1329e&lt;/wsa:RelatesTo&gt;&lt;wsa:To&gt;http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous&lt;/wsa:To&gt;&lt;wsse:Security&gt;&lt;wsu:Timestamp wsu:Id="Timestamp-4d37a6a5-9445-40d6-8660-a724999cc3bc"&gt;&lt;wsu:Created&gt;2011-03-23T06:39:57Z&lt;/wsu:Created&gt;&lt;wsu:Expires&gt;2011-03-23T06:44:57Z&lt;/wsu:Expires&gt;&lt;/wsu:Timestamp&gt;&lt;/wsse:Security&gt;&lt;/soap:Header&gt;&lt;soap:Body&gt;&lt;soap:Fault&gt;&lt;faultcode xmlns:q0="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"&gt;q0:Security&lt;/faultcode&gt;&lt;faultstring&gt;Header http://schemas.xmlsoap.org/ws/2004/08/addressing:Action for ultimate recipient is required but not present in the message.&lt;/faultstring&gt;&lt;faultactor&gt;http://webservice.client.com/cir.asmx&lt;/faultactor&gt;&lt;/soap:Fault&gt;&lt;/soap:Body&gt;&lt;/soap:Envelope&gt;
  </code></pre>