Web Service Example
Any application can have a Web Service component.
The creation of a Web Service is independent of the programming language used.
In this chapter we will show how to create a Web Service using the PHP SOAP extension.
SOAP has two modes of operation, NO-WSDL and WSDL.
- **NO-WSDL mode:** uses parameters to pass the information to be used.
- WSDL mode: Uses the WSDL filename as a parameter and extracts the information required by the service from the WSDL.
An example: PHP Web Service
Before starting the example, we need to confirm whether PHP has the SOAP extension installed. Check phpinfo; the following information indicates that the SOAP extension is installed:

In this example we will use PHP SOAP to create a simple Web Service.
Server side Server.php The file code is as follows:
"http://localhost/soap/Server.php","uri"=>"Server.php"));
// Export all functions in SiteInfo class
$s->setClass("SiteInfo");
// Process a SOAP request, call necessary functions, and send back a response.
$s->handle();
?>
Client Side Client.php The file code is as follows:
"http://localhost/soap/Server.php",'uri'=>'Server.php'));
// Call function
$result1 = $soap->getName();
$result2 = $soap->__soapCall("getUrl",array());
echo $result1."
";
echo $result2;
} catch(SoapFault $e){
echo $e->getMessage();
}catch(Exception $e){
echo $e->getMessage();
}
Now if we visit http://localhost/soap/Client.php, the output is as follows:
