Creating a Web Service with NuSOAP

At and, you will find NuSOAP, one of the best-known SOAP classes for PHP. Some might even know its predecessor, SOAPx4. For some time, releases weren't done very often, but now the project is active again. Nevertheless, you might be better off to check the Concurrent Versions System (CVS) system for the most recent code. Even though you might find several files there, nusoap.php is the one you want.

Calling an XML-RPC Web Service

  require_once 'nusoap.php';
  $soap = new soap_server;
  function add($a, $b) {
    return $a + $b;

As of this writing, NuSOAP only works under PHP 4, but a PHP 5 port is rumored to be under way.

Creating a Web Service with NuSOAP is really simple because the module takes care of all the painful things, including SOAP. Just follow these steps:

  1. Write the function you want to expose as a web method
  2. Instantiate the soap_server class
  3. Register your function with the SOAP server
  4. Call the service() method and submit $HTTP_RAW_POST_DATA as the parameter

This code implements a SOAP server using NuSOAP. Figure shows the output in the browser when you are trying to call the Web Service directly from the client. The error message says that the XML was emptyof course, because we didn't send a request!

This error message is a good signthe script seems to work (so far).