Monday, September 6, 2010

Article | Nusoap web service file transfer

What is Web Service?

Web services are frequently just Application Programming Interfaces (API) or web APIs that can be accessed over a network, such as the Internet, and executed on a remote system hosting the requested services. In common usage the term refers to clients and servers that communicate over the Hypertext Transfer Protocol (HTTP) protocol used on the web. Web Services use Extensible Markup Language (XML) messages that follow the Simple Object Access Protocol (SOAP) In PHP most easy way to use web services is using Nusoap library. NuSOAP is a powerful API developed for the PHP platform. It allows you to build both Web service clients and servers. One of the great features of NuSOAP is the built-in WSDL support.





What is Nusoap Web Service?

Nusoap is php classes library that is developed by http://sourceforge.net/projects/nusoap/ .A web services that is created with the help of nusoap php classes is called Nusoap web service.




What is Nusoap Web Service Authentication?

In any web service that is not free web service requires user authentication.If user authentication is not set in nusoap web service server than it can be access by any one from web site or desktop application.In general authentication of user is just check with username and password provided by user if it does not match then web service ask for user credentials for accessing service.




  1. <?php

  2. //include required class for build nnusoap web service server

  3. require_once('../lib/nusoap.php');

  4. // Create server object

  5. $server = new soap_server();

  6. // configure WSDL

  7. $server->configureWSDL('File Transfer Using Nusoap', 'urn:fileTransferwsdl');

  8. // Register the method to expose

  9. $server->register('transfer_file',// method

  10. array('filename' => 'xsd:string','fileAsEndcodedString' => 'xsd:string'),// input parameters

  11. array('return' => 'xsd:string'),// output parameters

  12. 'urn:fileTransferwsdl',// namespace

  13. 'urn:fileTransferwsdl#transferFile',// soapaction

  14. 'rpc',// style

  15. 'encoded',// use

  16. 'Transfer any file using web service'// documentation

  17. );




client.php


  1. <?php

  2. // includes nusoap class

  3. require_once('../lib/nusoap.php');

  4. // Create object

  5. $client = new nusoap_client('http://localhost:80/webservice_file_transfer/nusoap/server/server.php?wsdl', true);

  6. // Check for an error

  7. $err = $client->getError();

  8. if ($err) {

  9. // error if any

  10. echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';

  11. }

  12. // Call mathod

  13. $filepath="D:/NIK/MyPictures/myphoto/nik.jpg"; // example c:imagesmypic.jpg

  14. $fileString=base64_encode(fread(fopen($filepath, "r"), filesize($filepath)));

  15. $result = $client->call('transfer_file', array('filename' => 'nik.jpg','fileAsEndcodedString'=>$fileString));

  16. // fault if any

  17. if ($client->fault) {

  18. echo '<h2>Fault</h2><pre>';

  19. print_r($result);

  20. echo '</pre>';

  21. } else {

  22. // Check for errors

  23. $err = $client->getError();

  24. if ($err) {

  25. // Display the error

  26. echo '<h2>Error</h2><pre>' . $err . '</pre>';

  27. } else {

  28. // Display the result

  29. echo '<h2>Result</h2><pre>';

  30. print_r($result);

  31. echo '</pre>';

  32. }

  33. }

  34. //Display the request and response

  35. echo '<h2>Request</h2>';

  36. echo '<pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';

  37. echo '<h2>Response</h2>';

  38. echo '<pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';

  39. //Display the debug messages

  40. echo '<h2>Debug</h2>';

  41. echo '<pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';

  42. ?>

Loading...

Comments :

0 comments to “ Nusoap web service file transfer ”

Top Views

BloggerTipsTemplates

CHICKLETS

Enter your email address:

Delivered by FeedBurner

Followers