Consuming a Web Service with NuSOAP


Actually, using a NuSOAP service is even easier than creating one. You just have to load the WSDL file and then get a so-called proxy class: That's a local class that behaves just as if the Web Service is a local class, too. So, you can call the Web Service's methods directly, and NuSOAP takes care of all the rest (including opening a connection to the remote server, assembling and parsing XML, and so on).

To do this, the soapclient class (without the underscore character) must be instantiated, and then the getProxy() method creates the proxy class. The code implements this for the demo service from the previous example. Note the URL of the WSDL file: It's the Web Service's URL plus ?wsdl appended to the end; change the URL accordingly for your system.

Consuming the Web Service with NuSOAP (wsdl-nusoap-client.php)
 <?php   require_once 'nusoap.php';   $soap = new soapclient('http://localhost/     wsdl-nusoap-server.php?wsdl', true);   $proxy = $soap->getProxy();   $result = $proxy->add(47, 11);   echo "47 + 11 = $result"; ?> 

NOTE

Appending ?wsdl to the URL to get the WSDL description of a Web Service is an idea borrowed from Microsoft .NET. However, there the appendix is not case sensitive, whereas NuSOAP requires it to be in lowercase letters. Keep this in mind when working cross-platform.


WARNING

On some systems, NuSOAP has problems when PHP is configured as a common gateway interface (CGI), not as a module built in to the web server. You then see strange paths in the WSDL file.





PHP Phrasebook
PHP Phrasebook
ISBN: 0672328178
EAN: 2147483647
Year: 2005
Pages: 193

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net