PHP如何访问SOAP?
PHP如何访问SOAP的webservice?
需要SOAP函数??
需要SOAP函数??
作者: woshimajia0003 发布时间: 2010-11-06
server2.php服务端
PHP code
client.php客户端
PHP code
PHP code
<?php /** * 实现业务逻辑的类,此类是一个普通类 * */ class test { /** * 返回一个字符串:Hello World! * * @return string */ public function returnString(){ return "Hello World!"; } public function returnArray($array) { return array( array('id'=>0,'name'=>'a'), array('id'=>1,'name'=>'b'), array('id'=>2,'name'=>'c'), $array ); } public function sum($a,$b) { return $a+$b; } } /** * 创建Server对象 */ $arrOptions = array('uri'=>'http://example.com/'); //设置命名空间 $objSoapServer = new SoapServer(null,$arrOptions); /** * 注册Basic类的所有方法 */ $objSoapServer->setClass("test"); /** * 处理请求 */ $objSoapServer->handle(); ?>
client.php客户端
PHP code
<?php /** * Client端,首先创建Client对象 */ $arrOptions = array('uri'=>'http://example.com/', //设置命名空间 'location'=>'http://localhost/test_/xmlrpc/server/server2.php', //设置Server地址 'trace'=>true); $objSoapClient = new SoapClient(null,$arrOptions); /** * 远程调用 */ echo "<pre/>"; //try{ // $strReturn = $objSoapClient->returnString(); //}catch(Exception $e){ //} //echo $strReturn; $strReturn2 = $objSoapClient->returnArray(array('id'=>4,"name"=>"d")); print_r($strReturn2); $strReturn3 = $objSoapClient->sum(3,4); print_r($strReturn3); ?>
作者: ihefe 发布时间: 2011-03-14