标签:
服务端代码
<?php ini_set("soap.wsdl_cache_enabled", "0"); //ini_set(‘display_error‘,off); //导入几个重要的nusoap_base,nusoap_fault,soap_fault,nusoap_xmlschema,XMLSchema,soapval,soap_transport_http,nusoap_server,soap_server,wsdl,nusoap_parser,soap_parser,nusoap_client,soapclient类 require_once ("lib/nusoap.php"); $server = new soap_server; //避免乱码 $server->soap_defencoding = ‘UTF-8‘; //切换是否解析器解码元素内容 $server->decode_utf8 = false; //XML的编码格式 $server->xml_encoding = ‘UTF-8‘; //打开wsdl支持 $server->configureWSDL(‘wlzx_wsdl‘, ‘‘); //模式信息 $server->wsdl->schemaTargetNamespace = ‘urn:wlzx_wsdl‘; //获取数据库数据进行返回 $server->register(‘getTestData‘, //方法名 array("id" => "xsd:string"), //参数,默认为"xsd:string" array("return" => "xsd:string", ), //输出参数 "urn:wlzx_wsdl", //名字空间 "urn:wlzx_wsdl#getTestData", //名字空间#要操作的函数名 "rpc", //style "encoded", //use "获取test的数据" //说明 ); //返回值,默认为"xsd:string" //isset 检测变量是否设置 $getPost = file_get_contents("php://input"); //service 处理客户端输入的数据 $server->service($getPost); //获取数据 function getTestData($id){ return "Hello, { $id } !"; } ?>
客户端
<?php
error_reporting(E_ERROR);
require_once ("lib/nusoap.php");
$client = new nusoap_client(‘http://localhost/server.php?wsdl‘, true);
$client->soap_defencoding = ‘UTF-8‘;
$client->decode_utf8 = false;
$client->xml_encoding = ‘UTF-8‘;
$result = $client->call(‘getTestData‘, array(‘id‘=>‘你‘));
//print_r($client); 得到请求与响应详细内容
if (! $err = $client->getError ()) {
echo " 返回结果: ", $result;
} else {
echo " 调用出错: ", $err;
}
?>
标签:
原文地址:http://www.cnblogs.com/sixiong/p/4939404.html