WebService nusoap實例(php)

服務端: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

 php

相關文章
相關標籤/搜索