2. Buatlah suatu webservice yang berisi fungsi untuk menghitung penjumlahan dua buah nilai integer.
Server-1.php
require_once('C://wamp/www/sister/lib/nusoap.php');
$server = new soap_server();
$server->register('square');
$server->register('add');
function hello($nama) {
if (!$nama) {
return new soap_fault('client','','Harus ada nilainya','');
}
$hasil = "Hello, ".$nama;
return $hasil;
}
function square($x) {
$hasil = 'Hasil kuadrat '.$x.' = '.($x*$x);
return ($hasil);
}
function add($y, $z) {
$hasil = 'Hasil penjumlahan kedua bilangan = '.($y+$z);
return ($hasil);
}
$server->service($HTTP_RAW_POST_DATA);
exit();
?>
Client-1.php
require_once('C://wamp/www/sister/lib/nusoap.php');
$x = $_GET['x'];
$param = array('x' => $x);
$client = new soapclient('http://localhost/Sister/server-1.php');
$response = $client->call('square',$param);
if ($client->fault) {
echo "FAULT : Code : {$client->faultcode}
";
";
echo "string : {$client->faultstring}";
}
else {
echo $response;
}
?>
Screenshot
Client-2.php
require_once('C://wamp/www/sister/lib/nusoap.php');
$y = $_GET['y'];
$z = $_GET['z'];
$param = array('z' => $z, 'y' => $y);
$client = new soapclient('http://localhost/Sister/server-1.php');
$response = $client->call('add',$param);
if ($client->fault) {
echo "FAULT : Code : {$client->faultcode}
";
";
echo "string : {$client->faultstring}";
}
else {
echo $response;
}
?>
Screenshot
0 comments:
Post a Comment