Develop A Web Service in 5 Minutes Using Nusoap Library: Sanil S Technology Evangelist
Develop A Web Service in 5 Minutes Using Nusoap Library: Sanil S Technology Evangelist
Develop A Web Service in 5 Minutes Using Nusoap Library: Sanil S Technology Evangelist
Sanil S
Technology Evangelist
http://www.iamatechie.com
My portfolio
<?xml version="1.0"?>
Soap envelope
<SOAP-ENV:Envelope SOAP-
ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-
ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-
ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/1999/XMLSchema"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">
<SOAP-ENV:Body>
< m:getCityNameResponse xmlns:m="http://www.soapware.org/">
<Result xsi:type="xsd:string">Kollam</Result>
</ m:getCityNameResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Soap body
SOAP Fault
HTTP/1.1 500 Server Error
Connection: close
Content-Length: 511 Http Response header
Content-Type: text/xml; charset=utf-8
Date: Wed, 28 Mar 2001 05:06:32 GMT
Server: UserLand Frontier/7.0-WinNT
<?xml version="1.0"?>
<SOAP-ENV:Envelope SOAP-
ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-
ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/1999/XMLSchema"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Client</faultcode>
<faultstring>Can't call getCityName because there are too many
parameters.</faultstring>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
What we need in short
➲ XML output is not always simplest to put in
PHP code
➲ The XML output is repetitive
➲ Most of us are lazy
➲ Less work is better
➲ In-Short what is needed is a class
which abstracts the SOAP messages
for us
NuSOAP Toolkit
➲ Several PHP toolkits available for SOAP
➲ NuSOAP usage is simple and efficient
➲ Object Oriented ...
➲ URL - http://dietrich.ganx4.com/nusoap/
➲ Author - Dietrich Ayala
➲ Has support for WSDL generation as well
A PHP Function
// Return the STD code for the City.
function getCityName ($pincode){
require_once('nusoap.php');
$server = new soap_server;
$server->register(getCityName');
$server->service
($_SERVER['HTTP_RAW_POST_DATA']);
exit();
SOAP Client
require_once('nusoap.php');
$param = array(‘pincode'=>’691003’);
$client = new soapclient
('http://localhost/service.php?wsdl');
$response = $client->call(‘getCityName', $param);