Writing a Web Service Server
The server you'll develop with NuSOAP exposes one method: RectangleArea. As the name suggests, this method calculates the area of a rectangle. Here's the procedure for developing the web service:
><?php // Pull in the NuSOAP code require_once('./nusoap-php5-0.9/lib/nusoap.php'); // Create the server instance $server = new soap_server(); // Initialize WSDL support $server->configureWSDL('mathwsdl', 'urn:mathwsdl'); // Register the RectangleArea method to expose it $server->register('RectangleArea', // method name array('L' => 'xsd:int', 'l' => 'xsd:int'), // input parameters array('area_r' => 'xsd:string'), // output parameters 'urn:mathwsdl', // namespace 'urn:RectangleAreawsdl#RectangleArea', // soapaction 'rpc', // style 'encoded', // use 'Calculate a rectangle area as (L*l)' // documentation ); // Define the RectangleArea method as a PHP function function RectangleArea($L, $l) { return 'The rectangle area is: ' .($L*$l); } // Use the request to invoke the service $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : ''; $server->service($HTTP_RAW_POST_DATA); ?>
A useful feature of NuSOAP is that it lets you verify that a web service exists and ensure that it exposes the methods you needwithout having to develop a client.
For example, accessing http://localhost/php/SOAP_MESSAGES/server.php reveals the web service WSDL for the web service you just created (note that you didn't have to write or generate a WSDL, but the WSDL is there, nonetheless), and the service method. Next, you can see that for the RectangleArea method name you can see a list containing the information you need to write a proper web service client. Figure 1 shows a screen capture of the WSDL and the method for the server.php sample web service.