PHP webservice example_PHP tutorial

WBOY
Release: 2016-07-13 17:48:24
Original
1057 people have browsed it

First of all, everyone needs to briefly understand what webservice is. Next, we will give two very simple examples. Webservice still cannot escape the server side and client side.

The environment I tested is: apache2.2.11 php5.2.10

Before doing this test, make sure that the soap extension has been turned on in your php configuration file, that is, extension=php_soap.dll;
OK now let’s experience webservice

//server side serverSoap.php

$soap = new SoapServer(null,array('uri'=>"http://192.168.1.179/"));//This uri is your SERVER ip.
$soap->addFunction('minus_func'); $soap->addFunction(SOAP_FUNCTIONS_ALL);
$soap->handle();

function minus_func($i, $j){
$res = $i - $j;
Return $res;
}

//client side clientSoap.php
try {
$client = new SoapClient(null,
array('location' =>"http://192.168.1.179/test/serverSoap.php",'uri' => "http://127.0.0.1/")
);
echo $client->minus_func(100,99);

} catch (SoapFault $fault){
echo "Error: ",$fault->faultcode,", string: ",$fault->faultstring;
}

This is an example of the client calling a server-side function. Let’s create a class.

//www.2cto.com server-side serverSoap.php
$classExample = array();

$soap = new SoapServer(null,array('uri'=>"http://192.168.1.179/",'classExample'=>$classExample));
$soap->setClass('chesterClass');
$soap->handle();

class chesterClass {
Public $name = 'Chester';

Function getName() {
          return $this->name;
}
}

//client side clientSoap.php

try {
$client = new SoapClient(null,
array('location' =>"http://192.168.1.179/test/serverSoap.php",'uri' => "http://127.0.0.1/")
);
echo $client->getName();

} catch (SoapFault $fault){
echo "Error: ",$fault->faultcode,", string: ",$fault->faultstring;
}

Author Fox Hero

http://www.bkjia.com/PHPjc/478417.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478417.htmlTechArticleFirst of all, we need to briefly understand what webservice is. Next, we will give two very simple examples. Webservice still cannot escape. Open the server side and client side. The environment I tested is: apache2.2.11...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!