How to use Web Service
Editor to share with you how to use Web Service, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Web Service is a platform-independent, low-coupling, self-contained, programmable web-based application that can be described, published, discovered, coordinated, and configured using the open XML (a subset of the standard general markup language) standard for developing distributed, interoperable applications.
Example
Before starting the instance, we need to determine whether PHP has the SOAP extension installed. Looking at phpinfo, the following message appears to indicate that the SOAP extension has been installed: in this example, we will use PHP SOAP to create a simple Web Service.
Server side
The Server.php file code is as follows:
/ / the SiteInfo class is used to process the request Class SiteInfo {/ * return website name * @ return string * * / public function getName () {return "good Linux";} public function getUrl () {return "https://www.yisu.com/"; }} / / create the SoapServer object $s = new SoapServer (null,array ("location" = > "http://localhost/soap/Server.php","uri"=>"Server.php"));// exports all functions in the SiteInfo class $s-> setClass (" SiteInfo "); / / process an SOAP request, call the necessary functions, and send back a response. $s-> handle (); client
The Client.php file code is as follows:
Try {/ / non-wsdl calls web service / / create SoapClient object $soap = new SoapClient (null,array ('location'= > "http://localhost/soap/Server.php",'uri'=>'Server.php')); / / call function $result1 = $soap- > getName (); $result2 = $soap- > _ soapCall (" getUrl ", array ()); echo $result1."; echo $result2;} catch (SoapFault $e) {echo $e-> getMessage ();} catch (Exception $e) {echo $e-> getMessage () }
At this point, we visit http://localhost/soap/Client.php and the output is as follows:
Https://www.yisu.com/ above is all the content of this article "how to use Web Service". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!