Web Services In Php

5,945 views
5,841 views

Published on

0 Comments
9 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
5,945
On SlideShare
0
From Embeds
0
Number of Embeds
30
Actions
Shares
0
Downloads
0
Comments
0
Likes
9
Embeds 0
No embeds

No notes for slide

Web Services In Php

  1. 1. PHP – Web Service using NuSOAP Harit Kothari [email_address]
  2. 2. Agenda <ul><li>NuSOAP </li></ul><ul><li>Setting up & running Web Service in 5 minutes </li></ul><ul><li>An example </li></ul>
  3. 3. NuSOAP <ul><li>PHP library classes </li></ul><ul><li>Rewritten version of SOAPx4 </li></ul><ul><li>Create & consume SOAP web services </li></ul><ul><li>Supports RPC & Document type services </li></ul><ul><li>Carries some limitations </li></ul>
  4. 4. Setting up & running Web Service in 5 minutes <ul><li>Download the NuSOAP library </li></ul><ul><li>Use the library </li></ul><ul><li>Define a unique namespace (or more, if required) </li></ul><ul><li>Define and instantiate a NuSOAP server object </li></ul><ul><li>Initialize WSDL with namespace (defined above) for the NuSOAP instance </li></ul><ul><li>Set result / output namespace schema </li></ul>
  5. 5. <ul><li>Register method(s) to be served by the Web Service </li></ul><ul><li>Define method(s) (used as web service) along with specified signature </li></ul><ul><li>Read and assign contents of standard input stream to raw post data </li></ul><ul><li>Send the result as a SOAP response over HTTP </li></ul>
  6. 6. Example <ul><li><?php require_once('lib/nusoap.php'); $ns = &quot; http://localhost:8000 &quot;; $server = new soap_server; $server->configureWSDL('fooMethod1',$ns); $server->configureWSDL('fooMethod2',$ns); $server->wsdl->schemaTargetNamespace=$ns; </li></ul>
  7. 7. Example continued <ul><li>$server->register('fooMethod1', array('param1' => 'xsd:string', 'param2' => 'xsd:string' ), array('return' => 'xsd:boolean'), $ns ); </li></ul><ul><li>$server->register('fooMethod2', array('param1' => 'xsd:string', 'param2' => 'xsd:string' ), array('return' => 'xsd:boolean'), $ns); </li></ul>
  8. 8. Example continued <ul><li>function fooMethod1($param1, $param2) { // some statements... return true; // or false; } </li></ul><ul><li>function fooMethod2($param1, $param2) { // some statements... return true; // or false; } </li></ul>
  9. 9. Example continued <ul><li>$HTTP_RAW_POST_DATA = file_get_contents(&quot;php://input&quot;); $server->service($HTTP_RAW_POST_DATA); ?> </li></ul><ul><li>Suppose above file is stored as ws.php on localhost. </li></ul>
  10. 10. <ul><li>The WSDL is http://localhost:8000/ws.php?wsdl </li></ul><ul><li>Also, try opening http://localhost:8000/ws.php ! </li></ul>
  11. 11. References <ul><li>NuSOAP http://sourceforge.net/projects/nusoap/ </li></ul><ul><li>PHP Wrappers http://www.php.net/wrappers.php </li></ul>

×