SOAP XML webservice nusoap library

donwload library nusoap pada url http://sourceforge.net/projects/nusoap/

<?php
function kurs($dollar){
 return 9500 * $dollar;
}

require('lib/nusoap.php');
$server = new soap_server();
$server->configureWSDL("Kurs","urn:kursService");
$server->register(
 "kurs",
 array("dollar"=>"xsd:int"),
 array("return"=>"xsd:long"),
 "urn:kursService",
 "urn:kursService#kurs"
);

$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA)?$HTTP_RAW_POST_DATA : 'gagal';
$server->service($HTTP_RAW_POST_DATA);

?>

tampilan dari webservice

tampilan dari wsdl

 

Contoh client dari bahasa PHP

<?php
require('lib/nusoap.php');
?>
<html>
<head><title>client kurs</title></head>
<body>
<form action="<?= $_SERVER['PHP_SELF'] ?>" method='post'>
 Dolar <input type='text' name='txtDollar'>
 <input type='submit' name='submit' value='Rp' >
</form>
<?php
$url = "http://localhost/soap/kurs.php";

if($_POST['submit']){

 $client = new nusoap_client($url,false);

 $result = $client->call(
 "kurs", array('dollar'=>$_POST['txtDollar'])
 );

 $err = $client->getError();
 if($err){
 echo "<b>Error".$err."</b>";
 } else {
 echo "<b>Rupiah: ".$result."</b>";
 }

}
?>
</body>
</html>

Published by

G3n1k

just to remember what i had known :)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s