本篇內(nèi)容介紹了“php webservice怎么使用”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠?qū)W有所成!
創(chuàng)新互聯(lián)建站主營濰坊網(wǎng)站建設的網(wǎng)絡公司,主營網(wǎng)站建設方案,重慶APP開發(fā)公司,濰坊h5重慶小程序開發(fā)公司搭建,濰坊網(wǎng)站營銷推廣歡迎濰坊等地區(qū)企業(yè)咨詢
我測試的環(huán)境為:apache2.2.11 php5.2.10
做這個測試之前,要確認你的php配置文件中已經(jīng)將soap擴展打開,即extension=php_soap.dll;
OK 現(xiàn)在我們來體驗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; }
這是客戶端調(diào)用服務器端函數(shù)的例子,我們再搞個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 webservice怎么使用”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關的知識可以關注創(chuàng)新互聯(lián)網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實用文章!