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 get started with Web Service

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

Share

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

How to start Web Service, in view of this problem, this article introduces the corresponding analysis and solutions in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.

Reading Web Services makes your application a Web application. Web Services is published, found, and used through Web.

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 requests Class SiteInfo {/ * return website name * @ return string * * / public function getName () {return "Linux should learn";} public function getUrl () {return "www.linuxprobe.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 ();} this is the answer to the question on how to get started with Web Service. I hope the above content can be of some help to you. If you still have a lot of doubts to solve, you can follow the industry information channel for more related knowledge.

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

Internet Technology

Wechat

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

12
Report