Web Service Client ini akan mengkonsumsi Web Service PHP NUSOAP seperti yang diterangkan pada halaman Web Service PHP NUSOAP
Copy library NUSOAP ke dalam direktori lib
Buat file webservice wsclientphp.php, tuliskan kode program berikut :
<html> <head></head> <body> <table width="700" border="1" cellspacing="2" cellpadding="3"> <tr> <td>ID</td> <td>Name</td> <td>Description</td> <td>Date</td> <td>Price</td> <td> </td> </tr> <?php require("lib/nusoap.php"); $url="http://localhost/ws/ws.php"; $client=new soapclient($url); $result=$client->call("getTb",array()); if($result!=null){ for($i=0;$i<sizeof($result);$i++){ ?> <tr> <td><?php echo $result[$i]['id']; ?> </td> <td><?php echo $result[$i]['nm']; ?> </td> <td><?php echo $result[$i]['dsc']; ?> </td> <td><?php echo $result[$i]['dt']; ?> </td> <td><?php echo $result[$i]['prc']; ?> </td> <td><a href="wsclientphpedit.php?id=<?php echo $result[$i]['id']; ?>">Edit</a> <a href="wsclientphpdelete.php?id=<?php echo $result[$i]['id']; ?>">Del</a> </td> </tr> <?php } } ?> </table> <br /> <a href="wsclientphpadd.php">Add</a> </body> </html>
Buat file webservice wsclientphpadd.php, tuliskan kode program berikut :
<?php if ($_POST['button'] == 'Save') { require('lib/nusoap.php'); $url="http://localhost/ws/ws.php"; $client=new soapclient($url); $result=$client->call("insertTb", array("id"=>$_POST['id'],"nm"=>$_POST['nm'],"dsc"=>$_POST['dsc'],"dt"=>$_POST['dt'],"prc"=>$_POST['prc'])); $err=$client->getError(); if($err){ echo "error"; } header("location:wsclientphp.php"); } ?> <html> <head></head> <body> <form id="form1" name="form1" method="post" action=""> <table width="300" border="1" cellspacing="2" cellpadding="3"> <tr> <td>ID</td> <td><label> <input name="id" type="text" id="id" /> </label></td> </tr> <tr> <td>Name</td> <td><label> <input name="nm" type="text" id="nm" /> </label></td> </tr> <tr> <td>Description</td> <td><label> <input name="dsc" type="text" id="dsc" /> </label></td> </tr> <tr> <td>Date</td> <td><label> <input name="dt" type="text" id="dt" /> </label></td> </tr> <tr> <td>Price</td> <td><label> <input name="prc" type="text" id="prc" /> </label></td> </tr> <tr> <td> </td> <td><label> <input name="button" type="submit" id="button" value="Save" /> </label></td> </tr> </table> </form> </body> </html>
Buat file webservice wsclientphpedit.php, tuliskan kode program berikut :
<?php if ($_POST['button'] == 'Save') { require('lib/nusoap.php'); $url="http://localhost/ws/ws.php"; $client=new soapclient($url); $result=$client->call("updateTb", array("id"=>$_POST['id'],"nm"=>$_POST['nm'],"dsc"=>$_POST['dsc'],"dt"=>$_POST['dt'],"prc"=>$_POST['prc'])); $err=$client->getError(); if($err){ echo "error"; } header("location:wsclientphp.php"); } ?> <html> <head></head> <body> <?php require("lib/nusoap.php"); $url="http://localhost/ws/ws.php"; $client=new soapclient($url); $result=$client->call("getTb",array()); if($result!=null){ for($i=0;$i<sizeof($result);$i++){ if ($result[$i]['id'] == $_GET['id']) { $id = $result[$i]['id']; $nm = $result[$i]['nm']; $dsc = $result[$i]['dsc']; $dt = $result[$i]['dt']; $prc = $result[$i]['prc']; } } } ?> <form id="form1" name="form1" method="post" action=""> <table width="300" border="1" cellspacing="2" cellpadding="3"> <tr> <td>ID</td> <td><label> <input name="id" type="text" id="id" value="<?php echo $id; ?>" readonly /> </label></td> </tr> <tr> <td>Name</td> <td><label> <input name="nm" type="text" id="nm" value="<?php echo $nm; ?>" /> </label></td> </tr> <tr> <td>Description</td> <td><label> <input name="dsc" type="text" id="dsc" value="<?php echo $dsc; ?>" /> </label></td> </tr> <tr> <td>Date</td> <td><label> <input name="dt" type="text" id="dt" value="<?php echo $dt; ?>" /> </label></td> </tr> <tr> <td>Price</td> <td><label> <input name="prc" type="text" id="prc" value="<?php echo $prc; ?>" /> </label></td> </tr> <tr> <td> </td> <td><label> <input name="button" type="submit" id="button" value="Save" /> </label></td> </tr> </table> </form> </body> </html>
Buat file webservice wsclientphpdelete.php, tuliskan kode program berikut :
<?php require('lib/nusoap.php'); $url="http://localhost/ws/ws.php"; $client=new soapclient($url); $result=$client->call("deleteTb", array("id"=>$_GET['id'])); $err=$client->getError(); if($err){ echo "error"; } header("location:wsclientphp.php"); ?>
Hasilnya dapat dilihat pada url : localhost/wsclient/wsclientphp.php