YouTip LogoYouTip

Ws Example

Web Service Example | Rookie Tutorial

Web Service Example | Rookie Tutorial

Rookie Tutorial β€” Learn not just technology, but dreams!

Web Service Tutorial

Web Services TutorialWeb Services IntroductionWhy Use Web Services?Web Services Platform ElementsWeb Service ExampleWeb Services Summary

Web Services Platform Elements

Web Services Summary

Deep Dive

Web Services
web service
software
Web Services
Web Service
programming
programming languages
network
computer hardware
computer

Web Service Example


Any application can have a Web Service component.

The creation of a Web Service is independent of the programming language used.

In this section, we will introduce how to create a Web Service using PHP's SOAP extension.

SOAP has two operation modes: NO-WSDL and WSDL.

  • NO-WSDL mode: Uses parameters to pass the required information.
  • WSDL mode: Uses a WSDL filename as a parameter and extracts the necessary service information from the WSDL.

An Example: PHP Web Service

Before starting the example, we need to confirm whether the SOAP extension is installed in PHP. Check phpinfo; if you see the following information, it means the SOAP extension is already installed:

Image 3

In this example, we will use PHP SOAP to create a simple Web Service.

Server-side Server.php file code is as follows:

"http://localhost/soap/Server.php","uri"=>"Server.php")); // Export all functions from SiteInfo class $s->setClass("SiteInfo"); // Process a SOAP request, call necessary functions, and send back a response. $s->handle(); ?>

Client-side Client.php file code is as follows:

"http://localhost/soap/Server.php",'uri'=>'Server.php')); // Call functions $result1 = $soap->getName(); $result2 = $soap->__soapCall("getUrl",array()); echo $result1."
"; echo $result2; } catch(SoapFault $e){ echo $e->getMessage(); }catch(Exception $e){ echo $e->getMessage(); } ?>

Now, when we visit http://localhost/soap/Client.php, the output will be as shown below:

Image 4

← Wsdl PortsWs Platform β†’