PHP中soap的用法实例(2)

<?php
class service
{
  public function HelloWorld()
   {
      return  "Hello";
   }
  public  function Add($a,$b)
   {
      return $a+$b;
   }
}
$server=new SoapServer(null,array('uri' => "abcd"));
$server->setClass("service");
$server->handle();
?>


客户端:

复制代码 代码如下:

<?php
try{
 $soap = new SoapClient(null,array(
   "location" => "http://localhost/interface/soap.php",
   "uri"      => "abcd",  //资源描述符服务器和客户端必须对应
   "style"    => SOAP_RPC,
   "use"      => SOAP_ENCODED
      ));

echo $soap->Add(1,2);
}catch(Exction $e){
 echo print_r($e->getMessage(),true);
}
?>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/fc674d8bce32299d7f08b6313d2d0fdc.html