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:
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']
. '°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>
';
?>