服务端:ws_server.php

 

   
   
   
   
  1. /** 
  2.  * ws 服务端 
  3.  * @version nusoap-0.9.5 
  4.  * @link http://sourceforge.net/projects/nusoap/files/nusoap/0.9.5/nusoap-0.9.5.zip/download 
  5.  */ 
  6. require_once("../nusoap-0.9.5/lib/nusoap.php"); 
  7. header('Content-Type:text/html;charset=utf-8'); 
  8. //服务对象 
  9. $server = new soap_server(); 
  10. //生成wsdl 
  11. $server->configureWSDL("hello"); 
  12. //注册方法 
  13. $server->register("hello",array("user"=>"xsd:string","pwd"=>"xsd:integer"),array("return"=>"xsd:string")); 
  14. //处理请求和返回响应 
  15. $server->service($HTTP_RAW_POST_DATA); 
  16. //方法 
  17. function hello($user,$pwd){ 
  18.  return $user.$pwd

//客户端:ws_client.php

 

   
   
   
   
  1. /** 
  2.  * ws 客户端 
  3.  * @version nusoap-0.9.5 
  4.  * @link http://sourceforge.net/projects/nusoap/files/nusoap/0.9.5/nusoap-0.9.5.zip/download 
  5.  */ 
  6. require_once("../nusoap-0.9.5/lib/nusoap.php"); 
  7. header('Content-Type:text/html;charset=utf-8'); 
  8. //客户端对象 
  9. $client = new nusoap_client('http://localhost/test/ws_server.php?wsdl',true); 
  10. //调用方法 
  11. $res = $client->call("hello",array("user"=>"zsc","pwd"=>"123")); 
  12. if($err = $client->getError()){ 
  13.  //字符 =》html 实体 
  14.  echo htmlentities($err,ENT_QUOTES); 
  15. }else
  16.     echo $res