国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

php實現webservice實例

2024-05-04 23:26:55
字體:
來源:轉載
供稿:網友
這篇文章主要介紹了php實現webservice的方法,以實例形式講述了webservice的原理與實現技巧,需要的朋友可以參考下
 
 

本文實例講述了php實現webservice的方法。分享給大家供大家參考。具體實現方法如下:

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

這里的測試環境為:apache2.2.11 php5.2.10

做這個測試之前,要確認你的php配置文件中已經將soap擴展打開,即

復制代碼代碼如下:
extension=php_soap.dll;

OK 現在我們來體驗webservice

 

server端 serverSoap.php

復制代碼代碼如下:
$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;
}

這是客戶端調用服務器端函數的例子,我們再搞個class的。

 

server端 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端 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;
}

 

希望本文所述對大家的PHP程序設計有所幫助。


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 年辖:市辖区| 孟津县| 延吉市| 赤水市| 文成县| 上虞市| 衡水市| 四会市| 弥勒县| 长沙市| 枝江市| 永安市| 朔州市| 民权县| 浙江省| 东海县| 凤翔县| 涟水县| 石屏县| 定兴县| 华蓥市| 土默特右旗| 八宿县| 白朗县| 平山县| 炎陵县| 湖口县| 确山县| 顺平县| 萨迦县| 泰宁县| 宣化县| 湖北省| 平谷区| 武穴市| 大城县| 青海省| 屯留县| 白银市| 航空| 红桥区|