Kamis, 03 Mei 2012

Web Service Client PHP NUSOAP Mengakses Web Service VB.NET

Web Service Client - PHP Mengakses (Consume) Web Service VB.NET 

Web Service Client ini akan mengkonsumsi Web Service VB.NET seperti yang diterangkan pada halaman Web Service VB.NET

Copy library NUSOAP ke dalam direktori lib

Buat file webservice wsclientasp.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>&nbsp;</td>

</tr>

<?php

require_once('lib/nusoap.php');

$client = new soapclient('http://localhost:1495/ws/Service.asmx?wsdl', true);

$params = '';

$result = $client->call("getTb", $params);

//print_r($result['getTbResult']['diffgram']['NewDataSet']['admin']); //[0]['Nama']);

for ($i=0;$i<count($result['getTbResult']['diffgram']['NewDataSet']['tb']);$i++)

{

?>

<tr>

<td><?php echo $result['getTbResult']['diffgram']['NewDataSet']['tb'][$i]['id']; ?>&nbsp;</td>

<td><?php echo $result['getTbResult']['diffgram']['NewDataSet']['tb'][$i]['nm']; ?>&nbsp;</td>

<td><?php echo $result['getTbResult']['diffgram']['NewDataSet']['tb'][$i]['dsc']; ?>&nbsp;</td>

<td><?php echo $result['getTbResult']['diffgram']['NewDataSet']['tb'][$i]['dt']; ?>&nbsp;</td>

<td><?php echo $result['getTbResult']['diffgram']['NewDataSet']['tb'][$i]['prc']; ?>&nbsp;</td>

<td><a href="wsclientaspedit.php?id=<?php echo $result['getTbResult']['diffgram']['NewDataSet']['tb'][$i]['id']; ?>">Edit</a> <a href="wsclientaspdelete.php?id=<?php echo $result['getTbResult']['diffgram']['NewDataSet']['tb'][$i]['id']; ?>">Del</a> </td>

</tr>

<?php

}

?>

</table>



<br />

<a href="wsclientaspadd.php">Add</a>

</body>

</html>


Buat file webservice wsclientaspadd.php, tuliskan kode program berikut :

<?php

if ($_POST['button'] == 'Save')

{

require('lib/nusoap.php');

$client = new soapclient('http://localhost:1495/ws/Service.asmx?wsdl', true);

$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:wsclientasp.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>&nbsp;</td>

<td><label>

<input name="button" type="submit" id="button" value="Save" />

</label></td>

</tr>

</table>

</form>

</body>

</html>


Buat file webservice wsclientaspedit.php, tuliskan kode program berikut :

<?php

if ($_POST['button'] == 'Save')

{

require('lib/nusoap.php');

$client = new soapclient('http://localhost:1495/ws/Service.asmx?wsdl', true);

$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:wsclientasp.php");

}

?>

<html>

<head></head>

<body>

<?php

require_once('lib/nusoap.php');

$client = new soapclient('http://localhost:1495/ws/Service.asmx?wsdl', true);

$params = '';

$result = $client->call("getTb", $params);

//print_r($result['getAdminResult']['diffgram']['NewDataSet']['admin']); //[0]['Nama']);



if($result!=null){

for ($i=0;$i<count($result['getTbResult']['diffgram']['NewDataSet']['tb']);$i++){

if ($result['getTbResult']['diffgram']['NewDataSet']['tb'][$i]['id'] == $_GET['id'])

{

$id = $result['getTbResult']['diffgram']['NewDataSet']['tb'][$i]['id'];

$nm = $result['getTbResult']['diffgram']['NewDataSet']['tb'][$i]['nm'];

$dsc = $result['getTbResult']['diffgram']['NewDataSet']['tb'][$i]['dsc'];

$dt = $result['getTbResult']['diffgram']['NewDataSet']['tb'][$i]['dt'];

$prc = $result['getTbResult']['diffgram']['NewDataSet']['tb'][$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>&nbsp;</td>

<td><label>

<input name="button" type="submit" id="button" value="Save" />

</label></td>

</tr>

</table>

</form>

</body>

</html>


Buat file webservice wsclientaspdelete.php, tuliskan kode program berikut :

<?php

require_once('lib/nusoap.php');

$client = new soapclient('http://localhost:1495/ws/Service.asmx?wsdl', true);

$result=$client->call("deleteTb",

array("id"=>$_GET['id']));

$err=$client->getError();

if($err){

echo "error";

}

header("location:wsclientasp.php");

?>


Hasilnya dapat dilihat pada url : localhost/wsclient/wsclientasp.php