PHPBuilder - Building Web Services Using NuSOAP Toolkit Page 4



RSS Twitter
Articles Tricks And Hacks

Building Web Services Using NuSOAP Toolkit - Page 4

by: Mitja Kramberger
|
December 26, 2003

SOAP Client

In our client we're going to call webmethod "getWeather", with wanted city for input parameter (string). And if we get a valid response we'll output received data (degree, forecast). The code:

<?php    
    
/**************************************************************
    *  Description:
    *  Creates a simple SOAP Client (client.php).
    **************************************************************/
    
    // use form data
    
if ((string)$_GET['action'] == 'get_data') {
        
// includes nusoap classes
        
require('inc/nusoap.php');

        
// set parameters and create client
        
$l_aParam   = array((string)$_POST['city']);
        
$l_oClient  = new soapclient('http://somewhere.org/soap/server.php');
    
        
// call a webmethod (getWeather)
        
$l_stResult $l_oClient->call('getWeather'$l_aParam);
    
        
// check for errors
        
if (!$l_oClient->getError()) {
          
// print results
          
print '<h1>Current data for: '    $l_aParam[0
              . 
':</h1><ul><li>DEGREES: '   $l_stResult['degrees'
              . 
'&deg;C</li><li>FORECAST: ' $l_stResult['forecast'
              . 
'</li></ul>'
        }
        
// print error description
        
else {
          echo 
'<h1>Error: ' $l_oClient->getError() . '</h1>';
        }
    }

    
// output search form
    
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">
        </form>
    '
;
?>

« Previous Page
1
|
2
|
3
|
4
|
5
|
6
Next Page »

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
Mitja Kramberger

Comment:



Comment:

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