PHPBuilder - Building Web Services Using NuSOAP Toolkit Page 5

RSS Twitter

Building Web Services Using NuSOAP Toolkit - Page 5

by: Mitja Kramberger
December 26, 2003

For getting input parameter we output a simple form (city is a text input). If some data was sent, we then include NuSOAP toolkit. First we put string parameter into array, so that we can use it for calling webmethod. For a client we create object "soapclient" (argument is URL to the server) at line 14. With created client we can call our webmetod "getWeather" and we pass the parameter (form data in array).
And that's all. Finally we only need to check for errors (line 20) and if there're no errors we simple output data (lines 22-25). We have just created a simple SOAP client, with just a few line of code.

SOAP Client Using WSDL

With the above example we have created a simple SOAP client. We can also use WSDL to create proxy class, which will hold method (getWeather) of our web service. So basically the programmer only needs to know webmethods name and required parameters, and all this can be retrieved from WSDL. We can save WSDL file localy and use it. So let�s make a SOAP client using WSDL (look at server code to see how we generated WSDL).

     *  Description:
     *  Creates a simple SOAP Client using WSDL (client_wsdl.php).
     // use form data
if ((string)$_GET['action'] == 'get_data') {
// includes nusoap classes
// set parameters and create client
$l_oClient = new soapclient(
$l_oProxy  $l_oClient->getProxy();
// call a webmethod (getWeather)
$l_stResult $l_oProxy->getWeather((string)$_POST['city']);
// check for errors
if (!$l_oClient->getError()) {
// print results  
print '<h1>>Current data for: '  . (string)$_POST['city'
':</h1><ul><li>DEGREES: '   $l_stResult['degrees'
'&deg;C</li><li>FORECAST: ' $l_stResult['forecast'
// print error description
else {
'<h1>Napaka: ' $l_oClient->getError() . '</h1>';
// output search fclientorm
print '
        <form name="input" action="'
.$_SERVER['PHP_SELF'].'?action=get_data"  method="POST">
        Your city: <input type="text" name="city">
        <input type="submit" value="Search">

« Previous Page
Next Page »

Comment and Contribute

Your comment has been submitted and is pending approval.

Mitja Kramberger



(Maximum characters: 1200). You have characters left.