首先配置下PHP的soap环境支持:
找到php.ini文件
;extension=php_soap.dll
;always_populate_raw_post_data = -1
删除掉";" ,启用这两个扩展,重启apache服务器。
服务端:soap.php
<?php function getServiceIP(){ return "1.1.1.1"; } $soap = new SoapServer(null,array('uri'=>"vinson")); $soap->addFunction('getServiceIP'); $soap->addFunction(SOAP_FUNCTIONS_ALL); $soap->handle(); ?>
客户端:调用
try { $client = new SoapClient(null, array('location' =>"http://192.168.1.110/soap.php",'uri' => "vinson",'trace' =>1) ); echo $client->getServiceIP(); } catch (SoapFault $fault){ echo "Error: ",$fault->faultcode,", string: ",$fault->faultstring; }
当中的uri是匹配标志,两边要一致,随便什么值
location自然是需要调用的soap文件,此文件可置于另外一个网站里面
楼主一直提示
Error: Client, string: looks like we got no XML document
近乎抓狂,原来是有个扩展未开启。
;always_populate_raw_post_data = -1
vinson