当前位置: 首页 > 工具软件 > NuSOAP > 使用案例 >

php nusoap webservice,php使用nusoap创建WebService

鄢飞鸾
2023-12-01

service:

include_once("utils/lib/nusoap.php"); //加载nusoap库文件

$server = new soap_server(); //生成对象

$server->configureWSDL("screenshot_wsdl", "urn:screenshot_wsdl");

$server->register("screenshot", //调用方法

array( //输入参数

"key" => "xsd:string", //字符串类型

"arraykey" => "xsd:array", //数组类型

),

array( //输出参数

"returnstring" => "xsd:string",

"returnarray" => "xsd:array",

),

"urn:screenshot_wsdl", //名字空间

"urn:screenshot_wsdl#screenshot", //名字空间#要操作的函数名

"rpc", //style

"encoded", //use

"screenshot for webpage!"//说明

);

$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : ""; //Use the request to (try to) invoke the service

$server->service($HTTP_RAW_POST_DATA);

/**

* 处理截图请求方法

* @param $url

* @param $key

* @return array|soap_fault

*/

function screenshot($key, $arraykey)

{

return ['returnstring' => $key, 'returnarray' => $arraykey];

}

client:

include_once("utils/lib/nusoap.php"); //加载nusoap库文件

//设置参数数组

$para = array(

"key" => "test",

"arraykey" => [1, 2],

);

$client = new nusoap_client("http://localhost/jietu/soap_server.php?WSDL"); //访问的WebService地址

$return = $client->call('screenshot', $para); //发送请求

print_r($return); //输出返回结果

var_dump($client->getError()); //显示错误

 类似资料: