yinl_li 发表于 2018-12-21 08:56:40

WebService nusoap实例(php)

服务端:ws_server.php


[*]/**
[*] * 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_client.php


[*]/**
[*] * 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;
[*]}




页: [1]
查看完整版本: WebService nusoap实例(php)