2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > WebService-php- 2(17) webservice-php-17

WebService-php- 2(17) webservice-php-17

时间:2022-09-21 14:45:31

相关推荐

WebService-php- 2(17) webservice-php-17

php教程|php手册

WebService-php-,webservice-php-17,WebService-php-,webservice

php教程-php手册

WebService-php- 2(17),webservice-php-17

棋牌游戏网源码,ubuntu安装虾米音乐,搜索爬虫网站源码,bdiv php,兰州seo神奇lzw

wsdl实例

短信拦截码源码,vscode是哪国,ubuntu系统磁盘类型,tomcat多人聊天,sqlite 保留字,bootstrap table插件兼容性,egg是前端框架吗,郑州爬虫店,is int php,廊坊seo顾问,单本小说网站源码带后台,企业网页编程代码,3dh5模板,广告 页面无源码,怎么做通讯录管理系统,企业网站程序模板下载lzw

<!-- 元素定义 web service 使用的数据类型,WSDL 使用 XML Schema 语法来定义数据类型,也可以自定义Schema不包含的类型--><!-- 元素可定义每个消息的部件,以及相关联的数据类型.--><!-- 元素是最重要的 WSDL 元素.它可描述一个 web service、可被执行的操作,以及相关的消息.它告诉你去哪个WebService的连接点,扮演了一个控制者.--><!-- 元素为每个端口定义消息格式和协议细节--><!--包含一个或者多个port元素,每个port元素表示一个不同的Web服务-->

Server端示例:

有一家支付平台源码,ubuntu大于且小于,快手直播数据爬虫,php h,seo地图软件lzw

function test($x) {return $x;}$ss = new SoapServer(http://localhost/00/wsdl.xml);$ss->addFunction( est);$ss->handle();

Client调用:

$soap = new soapClient(http://localhost/00/wsdl.xml,array( race=>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文档

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。
相关阅读
扩展阅读