最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

php實(shí)現(xiàn)webservice實(shí)例

 更新時(shí)間:2014年11月06日 09:17:25   投稿:shichen2014  
這篇文章主要介紹了php實(shí)現(xiàn)webservice的方法,以實(shí)例形式講述了webservice的原理與實(shí)現(xiàn)技巧,需要的朋友可以參考下

本文實(shí)例講述了php實(shí)現(xiàn)webservice的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:

首先大家要簡單了解何謂webservice,接下來就做兩個(gè)非常簡單的例子,webservice還是逃不開server端與client端。

這里的測試環(huán)境為:apache2.2.11 php5.2.10

做這個(gè)測試之前,要確認(rèn)你的php配置文件中已經(jīng)將soap擴(kuò)展打開,即

復(fù)制代碼 代碼如下:
extension=php_soap.dll;

OK 現(xiàn)在我們來體驗(yàn)webservice

server端 serverSoap.php

復(fù)制代碼 代碼如下:
$soap = new SoapServer(null,array('uri'=>"http://192.168.1.179/"));//This uri is your SERVER ip.
$soap->addFunction('minus_func');                                                 //Register the function
$soap->addFunction(SOAP_FUNCTIONS_ALL);
$soap->handle();
function minus_func($i, $j){
    $res = $i - $j;
    return $res;
}
//client端 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;
}

這是客戶端調(diào)用服務(wù)器端函數(shù)的例子,我們?cè)俑銈€(gè)class的。

server端 serverSoap.php

復(fù)制代碼 代碼如下:
$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端 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;
}

希望本文所述對(duì)大家的PHP程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論

西乡县| 塘沽区| 紫金县| 沂源县| 浦江县| 紫阳县| 高要市| 博湖县| 中方县| 巧家县| 溧阳市| 诏安县| 锡林郭勒盟| 秦皇岛市| 甘谷县| 化德县| 卢湾区| 吉木乃县| 偃师市| 徐水县| 紫金县| 莱西市| 嘉义县| 罗甸县| 鄂伦春自治旗| 龙泉市| 天津市| 兖州市| 阳泉市| 通榆县| 平顶山市| 安新县| 广宗县| 涞水县| 永宁县| 高唐县| 兴化市| 阜康市| 光山县| 亳州市| 莱西市|