PHP web services with the NuSOAP libraryFulvio Corno, Dario Boninoe-lite Research GroupDipartimento di Automatica e InformaticaPolitecnico di TorinoTorino - Italyhttp://elite.polito.itv. 2.1, April 2, 2009Web services in PHPThe NuSOAP libraryLicenseOutline1Web services in PHP2The NuSOAP librarySOAP ServerSOAP ClientUsing WSDLError CheckingComplex Types3LicensePHP web services with the NuSOAP library2 / 39Web services in PHPThe NuSOAP libraryLicenseGoalsCreate and use Web Services using the RPC messaging modelBeing able to create a Web Service in PHP (server-side)Being able to call an existing Web Service from PHP code(client-side)Hiding, as much as possible, the creation of SOAP messages,and their decodingAvoid the difficulty of creating/editing WSDL filesPHP web services with the NuSOAP library3 / 39Web services in PHPThe NuSOAP libraryLicensePotential SolutionsPhp comes with a “standard” SOAP libraryhttp://www.php.net/soaptutorial at http://devzone.zend.com/node/view/id/689The PEAR library has a SOAP modulehttp://pear.php.net/package/SOAPprobably the most updated, but not well documentedThe NuSOAP library (we will use this)http://sourceforge.net/projects/nusoap/PHP web services with the NuSOAP library4 / 39Web services in PHPThe NuSOAP libraryLicenseLimitationsAll considered libraries are easy to use when the input(s) andoutput of the web service are simple types (numbers, strings)Complex types are difficult to “teach” to the libraries, and theyare not fully supportedFor practical reasons, we will try to use only xsd:string typesPHP web services with the NuSOAP library5 / 39Web services in PHPThe NuSOAP libraryLicenseOutline1Web services in PHP2The NuSOAP librarySOAP ServerSOAP ClientUsing WSDLError CheckingComplex Types3LicensePHP web services with the NuSOAP library6 / 39Web services in PHPThe NuSOAP libraryLicenseNuSOAP characteristicsWritten in PHP (no new modules to install or configure)Simple object-oriented interfaceMay work with or without WSDL filesMay automatically generate a WSDL file for the servicePHP web services with the NuSOAP library7 / 39Web services in PHPThe NuSOAP libraryLicenseInstallationDownload fromhttp://sourceforge.net/projects/nusoap/Uncompress the file, and copy the lib directory under yourPHP projectIn your PHP files (client or server), import the needed classesrequire_once(’lib/nusoap.php’);PHP web services with the NuSOAP library8 / 39Web services in PHPThe NuSOAP libraryLicenseOutline1Web services in PHP2The NuSOAP librarySOAP ServerSOAP ClientUsing WSDLError CheckingComplex Types3LicensePHP web services with the NuSOAP library9 / 39Web services in PHPThe NuSOAP libraryLicenseSOAP ServerMinimal SOAP serverrequire_once(’lib/nusoap.php’) ;$server = new nusoap_server; // Create server instance$server->register( ’myFunction’ ) ;function myFunction($parameters) {. . .return $result;}// Use the request to (try to) invoke the service$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA)? $HTTP_RAW_POST_DATA : ’’;$server->service($HTTP_RAW_POST_DATA);PHP web services with the NuSOAP library10 / 39Document Outline
- Web services in PHP
- The NuSOAP library
- SOAP Server
- SOAP Client
- Using WSDL
- Error Checking
- Complex Types
- License
Add New Comment