Skip to content

Web Service

IT Notes → PHP @ December 22, 2020

  • Web Service is a standard way of interoperating between different software applications running on variety of platforms and/or frameworks.
  • SOAP – Simple Object Access Protocol.
  • RPC – Remote Procedure Call. It is the most common messaging pattern.
  • REST – Representational State Transfer. Each resource must be identified by a global identifier URI. To access these resources, clients communicate with the REST service by HTTP, and the server responds with a representation of the resource. They are not discoverable and hence has no WSDL. Websites that give RSS and RDFfeeds provide RESTful service. Delicious is an example which gives an XML ready to be consumed by SimpleXML. We pass the URL the username and password to obtain XML.
  • WSDL – Web Services Definition Language. It is a language for locating and describing web services.
  • UDDP – Universal Description Discovery and Integration. It is a directory service where we can register and search web services
  • NuSoap is a famous SOAP library in PHP.

 

Server:

//We have to first code the class MySoapServer with a function named method with parameter param and locate this code in server.php.
$options = array(uri' => http://example.org/soap/server/);
$server = new SoapServer(NULL, $options);
$server->setClass(MySoapServer);
$server->handle();

Client:

try
{
$options = array(
location => http://example.org/soap/server/server.php,uri => http://example.org/soap/server/,'trace'=1);
$client = new SoapClient(NULL, $options);               
//WSDL URI if working in WSDL mode with options as next parameter. Here not in WSDL mode so first parameter is NULL and options have to include location an URI. Last parameter with trace=1 will debug.
$results = $client->method(param);                 //Method from WSDL. Returns XML. You can loop through it.
echo $client->__getLastRequestHeaders();           //Request headers.
echo $client->__getLastRequest();                  //Request XML body.
}
catch (SoapFault $e)
{
echo $e->getMessage();
}

 

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x