Automatically Generating WSDL with NuSOAP

As mentioned previously, current Web Services do almost always use WSDL. Writing WSDL manually is a real pain and very error-prone, but most serious Web Services implementations for PHP can create WSDL automatically. However, because PHP is no strongly typed language, they need some help.

To do so with NuSOAP, the code from the previous section must be expanded a bit. First, a method configureWSDL() must be called to provide the name and the namespace of the service. Then, the signature of the method must be provided (which parameters go in, which go out). Then, the server is started. However, this time whether $HTTP_RAW_POST_DATA is set is checked or not. This is because when it is not set, the user has made a GET request, so there might be a chance that he just wants the WSDL description.

A WSDL-enabled Web Service with NuSOAP

  require_once 'nusoap.php';
  $soap = new soap_server;
  $soap->configureWSDL('AddService', 'http://php.');
  $soap->wsdl->schemaTargetNamespace = 'http://';
    array('a' => 'xsd:int', 'b' => 'xsd:int'),
    array('c' => 'xsd:int'),
  $soap->service(isset($HTTP_RAW_POST_DATA) ?
    $HTTP_RAW_POST_DATA : '');
  function add($a, $b) {
    return $a + $b;

Back to the WSDL: Figure shows the Web Service in the browser when called using GET. A click on the link shows some information about the add() method. In Figure 9.4, you see what happens when you append ?WSDL to the URL of the script (or click on the WSDL link): The WSDL for the service is automatically generated. Imagine if you had to do this manually...

Now NuSOAP automatically generates an info page for the service.

This WSDL is generated by NuSOAP, not by the programmer.

by BrainBellupdated