

Server.php
// load SOAP library
require_once('D:\wamp\www\nusoap-0.7.3\lib\nusoap.php');
//require_once('../lib/nusoap.php');
//require_once('D:/wamp/www/nusoap-0.7.3/samples/functions.php');
// load library that holds implementations of functions we're making available to the web service
// set namespace
$ns="http://localhost/";
// create SOAP server object
$server = new soap_server();
// setup WSDL file, a WSDL file can contain multiple services
$server->configureWSDL('Calculator',$ns);
$server->wsdl->schemaTargetNamespace=$ns;
// register a web service method
$server->register('ws_add',
array('int1' => 'xsd:integer','int2' => 'xsd:integer'), // input parameters
array('total' => 'xsd:integer'), // output parameter
$ns, // namespace
"$ns#ws_add", // soapaction
'rpc', // style
'encoded', // use
'adds two integer values and returns the result' // documentation
);
function ws_add($int1, $int2)
{
$total=$int1+$int2;
return $total;
}
// service the methods
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA)? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>
Client.php
require_once('D:/wamp/www/nusoap-0.7.3/lib/nusoap.php');
//require_once('../lib/nusoap.php');
$wsdl="http://localhost/nusoap-0.7.3/samples/server.php?wsdl";
$client=new soapclient($wsdl, 'wsdl');
$param=array('int1'=>'15', 'int2'=>'340');
$result=$client->call('ws_add', $param);
//echo "";
// Check for a fault
if ($client->fault)
{
echo 'Fault';
print_r($result);
}
else
{
// Check for errors
$err = $client->getError();
if ($err)
{
// Display the error
echo 'Error' . $err . '';
}
else
{
// Display the result
echo 'Result';
print_r($result);
echo '';
}
}
// Display the request and response
echo 'Request';
echo '' . htmlspecialchars($client->request, ENT_QUOTES) . '';
echo 'Response';
echo '' . htmlspecialchars($client->response, ENT_QUOTES) . '';
unset($client);
?>
No comments:
Post a Comment