- /**
- * ws 服務端
- * @version nusoap-0.9.5
- * @link http://sourceforge.net/projects/nusoap/files/nusoap/0.9.5/nusoap-0.9.5.zip/download
- */
- require_once("../nusoap-0.9.5/lib/nusoap.php");
- header('Content-Type:text/html;charset=utf-8');
- //服務對象
- $server = new soap_server();
- //生成wsdl
- $server->configureWSDL("hello");
- //註冊方法
- $server->register("hello",array("user"=>"xsd:string","pwd"=>"xsd:integer"),array("return"=>"xsd:string"));
- //處理請求和返回響應
- $server->service($HTTP_RAW_POST_DATA);
- //方法
- function hello($user,$pwd){
- return $user.$pwd;
- }
- /**
- * ws 客戶端
- * @version nusoap-0.9.5
- * @link http://sourceforge.net/projects/nusoap/files/nusoap/0.9.5/nusoap-0.9.5.zip/download
- */
- require_once("../nusoap-0.9.5/lib/nusoap.php");
- header('Content-Type:text/html;charset=utf-8');
- //客戶端對象
- $client = new nusoap_client('http://localhost/test/ws_server.php?wsdl',true);
- //調用方法
- $res = $client->call("hello",array("user"=>"zsc","pwd"=>"123"));
- if($err = $client->getError()){
- //字符 =》html 實體
- echo htmlentities($err,ENT_QUOTES);
- }else{
- echo $res;
- }
php