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.<?php//include required class for build nnusoap web service serverrequire_once('../lib/nusoap.php');// Create server object$server = new soap_server();// configure WSDL$server->configureWSDL('File Transfer Using Nusoap', 'urn:fileTransferwsdl');// Register the method to expose$server->register('transfer_file',// methodarray('filename' => 'xsd:string','fileAsEndcodedString' => 'xsd:string'),// input parametersarray('return' => 'xsd:string'),// output parameters'urn:fileTransferwsdl',// namespace'urn:fileTransferwsdl#transferFile',// soapaction'rpc',// style'encoded',// use'Transfer any file using web service'// documentation);
client.php
<?php// includes nusoap classrequire_once('../lib/nusoap.php');// Create object$client = new nusoap_client('http://localhost:80/webservice_file_transfer/nusoap/server/server.php?wsdl', true);// Check for an error$err = $client->getError();if ($err) {// error if anyecho '<h2>Constructor error</h2><pre>' . $err . '</pre>';}// Call mathod$filepath="D:/NIK/MyPictures/myphoto/nik.jpg"; // example c:imagesmypic.jpg$fileString=base64_encode(fread(fopen($filepath, "r"), filesize($filepath)));$result = $client->call('transfer_file', array('filename' => 'nik.jpg','fileAsEndcodedString'=>$fileString));// fault if anyif ($client->fault) {echo '<h2>Fault</h2><pre>';print_r($result);echo '</pre>';} else {// Check for errors$err = $client->getError();if ($err) {// Display the errorecho '<h2>Error</h2><pre>' . $err . '</pre>';} else {// Display the resultecho '<h2>Result</h2><pre>';print_r($result);echo '</pre>';}}//Display the request and responseecho '<h2>Request</h2>';echo '<pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';echo '<h2>Response</h2>';echo '<pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';//Display the debug messagesecho '<h2>Debug</h2>';echo '<pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';?>
|
Loading...
|
Comments :
Post a Comment
Enter any comments