Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Web Service

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report