您好,欢迎访问一九零五行业门户网

WebService-php- 2(17),webservice-php-17_PHP教程

webservice-php- 2(17),webservice-php-17wsdl实例

server端示例:
function test($x) {return $x;}$ss = new soapserver('http://localhost/00/wsdl.xml');$ss->addfunction('test');$ss->handle();
client调用:
$soap = new soapclient('http://localhost/00/wsdl.xml',array('trace'=>true));var_dump($soap->test('10086'));
传递和返回数组参数
如果传递或返回的参数为数组,可以在message标签中做说明.

xml-rpc调用
xml-rpc可以理解为简化版的soap,对数据的包装相对简洁.php.ini中,要打开extension=php_xmlrpc.dll
/*求和函数注意,rpc服务器在调用函数时,传的参数是这样的:array(0=>'函数名' , 1=>array(实参1,实参2,...实参n) , 2=>null)*/function hello() {return 'hello';}function sum($method , $args , $extra) {return array_sum($args);}// 创建rpc server$server = xmlrpc_server_create ();xmlrpc_server_register_method ($server , 'hello' , 'hello');xmlrpc_server_register_method ($server , 'sum' , 'sum');// 收取请求$request = $http_raw_post_data;//执行调用客户端的xml请求后获取执行结果$xmlrpc_response = xmlrpc_server_call_method($server, $request , null);//把函数处理后的结果xml进行输出header('content-type: text/xml');echo $xmlrpc_response;//销毁xml-rpc服务器端资源xmlrpc_server_destroy($server);
客户端:
class rpcclient {protected $url;public function __construct($url='' ) {$this->url = $url;}protected function query($request) {$context = stream_context_create(array('http' => array('method' => post,'header' => content-type: text/xml,'content' => $request)));$xml = file_get_contents($this->url, false, $context);return xmlrpc_decode($xml);}public function __call($method , $args) {$request = xmlrpc_encode_request($method , $args);return $this->query($request);}}$rpc = new rpcclient('http://localhost/00/rpcs.php');var_dump($rpc->hello());var_dump($rpc->sum(4,5,6));
webservice与json api的区别
webservice json api
数据封装xml json
复杂度 高  低
底层协议     不限  http
数据类型     可严格定义  不可严格定义
自说明        性自说明需额外api文档
http://www.bkjia.com/phpjc/993278.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/993278.htmltecharticlewebservice-php- 2(17),webservice-php-17 wsdl实例 ?xml version = ' 1.0 ' encoding = ' utf-8 ' ? definitionstargetnamespace = ' http://localhost/00/ ' xmlns:tns = ' http://lo...
其它类似信息

推荐信息