new obilog: gado-gado blog si obie

NuSoap – SOAP Toolkit for PHP

NuSOAP is a group of PHP classes that allow developers to create and consume SOAP web services. It does not require any special PHP extensions. The current release version (0.6.7) of NuSOAP at the time this was written (03-November-2004), supports much of the SOAP 1.1 specification. It can generate WSDL 1.1 and also consume it for use in serialization. NuSOAP is a rewrite of SOAPx4, provided by NuSphere and Dietrich Ayala. It is a set of PHP classes – no PHP extensions required – that allow developers to create and consume web services based on SOAP 1.1, WSDL 1.1 and HTTP 1.0/1.1.

This document describes how to obtain and install NuSOAP, then provides some samples to illustrate the capabilities of NuSOAP. It is by no means an exhaustive description of NuSOAP, but it is hopefully enough to get any PHP coder started. Programming with NuSOAP follows this up with more complex samples.

For Download Nu SOAP

Docs File : http://sourceforge.net/projects/nusoap/files/nusoap-docs/0.9.5/nusoap-docs-0.9.5.zip/download

Lib File : http://sourceforge.net/projects/nusoap/files/nusoap/0.9.5/nusoap-0.9.5.zip/download

Example :

I create simple webservice in Java

calc.java

package org.com.calc;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;

/**
*
* @author obiesan
*/
@WebService(name = "contohcalc", serviceName="calc", targetNamespace="urn:urlcalc")
public class calc {

@WebMethod(operationName = "cekkoneksi", action="urn:urlcalc#cekkoneksi")
public String cekkoneksi()
{
//TODO write your implementation code here:
return ("Nyambung nih");
}

@WebMethod(operationName = "tambah", action="urn:urlcalc#tambah")
public double tambah(@WebParam(name = "nilx")
double nilx, @WebParam(name = "nily")
double nily) {
//TODO write your implementation code here:
return (nilx+nily);
}

@WebMethod(operationName = "kurang", action="urn:urlcalc#kurang")
public double kurang(@WebParam(name = "nilx")
double nilx, @WebParam(name = "nily")
double nily) {
//TODO write your implementation code here:
return (nilx-nily);
}

@WebMethod(operationName = "bagi", action="urn:urlcalc#bagi")
public double bagi(@WebParam(name = "nilx")
double nilx, @WebParam(name = "nily")
double nily) {
//TODO write your implementation code here:
return (nilx/nily);
}

@WebMethod(operationName = "kali", action="urn:urlcalc#kali")
public double kali(@WebParam(name = "nilx")
double nilx, @WebParam(name = "nily")
double nily) {
//TODO write your implementation code here:
return (nilx*nily);
}
}

And for the client (php)

<?php

if(isset($_POST["submit"])){
 $param1=$_POST['param1'];
 $param2=$_POST['param2'];

 if(!is_string(array($param1,$param2))){
 require("lib/nusoap.php");

 //lihat alamat wsdlnya ubah localhost menjadi 127.0.0.1 dengan $namespacenya

 $url = "http://127.0.0.1:10328/contoh/calc";
 $namespace="urn:urlcalc";

 $client = new nusoap_client($url);
 //cek koneksi dulu
 $cek = $client->call("cekkoneksi","",$namespace);

 //inisial parameter
 $parameter = array("nilx"=>$param1,"nily"=>$param2);

 if($cek!=""){
 echo "<h3>Inputan kamu parameter 1 : ".$param1." dan parameter 2 : ".$param2."</h3><br>";
 echo $cek."<br><br>";

 //kata tambah, kurang, bagi, kali di dalam call itu merupakan nama operationname lihat di javanya
 //parameter disesuaikan dengan parameter di masing2 method di java

 $tambah = $client->call("tambah",$parameter, $namespace);
 $kurang = $client->call("kurang",$parameter, $namespace);
 $kali = $client->call("kali",$parameter, $namespace);
 $bagi = $client->call("bagi",$parameter, $namespace);

 echo "Hasil tambah : ".$tambah."<br>";
 echo "Hasil kurang : ".$kurang."<br>";
 echo "Hasil kali : ".$kali."<br>";
 echo "Hasil bagi : ".$bagi."<br>";

 }else
 echo "koneksi gagal";

 $er = $client->getError();

 if($er){
 echo "<h2>Error with soapclient creation : </h2><pre>".$er."</pre>";
 }
 }
 echo "<br><br><hr><br>";
}
?>

<form action="" method="POST">
 Parameter 1 : <input type="text" name="param1" value="masukkan nilai x" size="20" onclick="this.form.param1.value=''"><br>
 Parameter 2 : <input type="text" name="param2" value="masukkan nilai y" size="20" onclick="this.form.param2.value=''"><br>
 <input type="submit" value="hitung" name="submit">
</form>

    You can follow any responses to this entry through the RSS 2.0 feed.