Home > PHP > PHP + NuSoap: Calling webservice

PHP + NuSoap: Calling webservice

December 20th, 2008

In the last post i made an implementation example of a small webservice.
Now we see how to invoke it with few line of code, using the same library used to realize the server side implementation.

 In this example I want to display also all debug informations.

MyWebServiceClient.php
  1.  
  2. require_once('nusoap.php');
  3.  
  4. // Creating client instance
  5. $client = new soapclient('http://www.miosito.com/MyWebService.php');
  6. //Invoke remote method
  7. $result = $client->call('MyMethod',
  8.   array('param1' => 'Ciao ', 'param2' => 'a tutti'));
  9. //Display the result
  10. print_r($result);
  11.  
  12. // Display all request and response information for debug purpose
  13. echo '<h2>Request</h2>';
  14. echo '<code>'.htmlspecialchars($client-&gt;request, ENT_QUOTES) .'</code>';
  15.  
  16. echo '<h2>Response</h2>';
  17. echo '<code>'.htmlspecialchars($client-&gt;response, ENT_QUOTES) .'</code>';

All done! In this way we can invoke the webservice realized in the last post. It’s easy, isn’t it?

SociBook del.icio.us Digg Facebook Google Yahoo Buzz StumbleUpon

PHP , , ,

  1. No comments yet.
  1. No trackbacks yet.