xmlrpc编辑

官方URL:http://ws.apache.org/xmlrpc/xmlrpc2/index.html

本词条缺少名片图,补充相关内容使词条更完整,还能快速升级,赶紧来编辑吧!
xml rpc是使用http协议做为传输协议rpc机制,使用xml文本的方式传输命令和数据。一个rpc系统,必然包括2个部分:1.rpc client,用来向rpc server调用方法,并接收方法的返回数据;2.rpc server,用于响应rpc client的请求,执行方法,并回送方法执行结果。RPC是Remote Procedure Call的缩写,翻译成中文就是远程过程调用,是一种在本地的机器上调用远端机器上的一个过程(方法)的技术,这个过程也被大家称为“分布式计算”,是为了提高各个分立机器的“互操作性”而发明出来的技术。
外文名

xmlrpc
使    用

http协议
提    高

各个分立机器的“互操作性
建    立

在SUN RPC技术基础之上的
 

1简介编辑

按照“数据即程序”的观点来看,RPC无非是借助一些通信手段来互相传递数据(信息),所以她也是“高”层次的通信手段,无非是这种通信手段看起来更像是“过程的调用”,因为她往往以一个“函数”的面目示人,从而掩盖了她交换信息的实质。
在各种RPC技术中,我想应该以Sun的RPC最为著名,比较流行的网络文件系统NFS就是建立在SUN RPC技术基础之上的。
XMLRPC,顾名思义就是应用了XML(标准通用标记语言的子集)技术的RPC。
在Sun RPC中,调用双方传递的数据是二进制的,而在XMLRPC中数据将是XML格式的。那么为什么用XML而不用二进制呢?我想一方面应该是为了兼容更多的语言,因为这个世界上除了C/C++等编译语言,还有很多类似python,perljavascript等的脚本语言(有些文章也称其为“动态语言”,因为他们通常不需要自己管理内存),另一方面是为了隔离操作系统的差异,比如说Little Endian和Big Endian的差异等。基于种种原因,XMLRPC选择了XML这种中间语言作为其信息的格式,然后由各个语言负责将其转变成各自native(本土)的数据类型。关于为了兼容各个语言所发明的中间语言还有IDL(Interface Definition Language:接口定义语言),它被用于CORBA接口的定义。

2工作原理编辑

完整的需要参考xmlrpc规范
简单描述:
rpcclient的工作原理:rpcclient根据URL找到rpcserver -> 构造命令包,调用rpcserver上的某个服务的某个方法 -> 接收到rpcserver的返回,解析响应包,拿出调用的返回结果。
rpcserver的工作原理:启动一个webserver(在使用内置的webserver的情况下) -> 注册每个能提供的服务,每个服务对应一个Handler类 ->进入服务监听状态

3对应关系编辑

参考附录中test2.XmlRPCClient类与test2.JavaServer类。
在这里简单描述一下:
>xmlrpc中的Array类型,对应到java中的Vector类型
例如:在RPC Server中的某个服务方法的返回值的声明类型是String[],但在Client中接收到的将是Vector对象;
反之,如果Client传送过去的调用参数为String[],但在RPC Server中所接收到的将是Vector对象
当然,如果我们不使用String[],直接声明为Vector,也是可以的。
>xmlrpc中的struct类型,对应到java中的Hashtable类型
> 其它的类型,如:String,int,double,boolean,Date等,都比较好对应。需要注意的是:在rpc Client中,如果使用到int/double/boolean这些基本类型时,需要将他们封装成一个相应的Object,例如:Integer /Double/Boolean

4可用版本编辑

xml rpc client和xml rpc server都有很多版本的实现。一般而言,一个实现版本都会同时实现client/server。但由于都满足xml rpc规范,从理论上讲,任何一个版本的rpc client实现与任何一个版本的rpc server都能配套使用。
更进一步,由于xml rpc以xml文本的方式,使用http协议传输,所以与编程语言无关。例如:rpc client的已实现版本包括了:perl,php,python,c/c++,java,等等;rpc server的实现语言包括perl,java,等。
同一种编程语言所实现的版本也不止一个。例如java版的实现有:Marque的xmlrpc实现,apache的xmlrpc 实现

5实现版本编辑

这个sample中,假设所传输的object都实现了XmlRPCSerializable接口。这个例子的目的是:模拟unionmon中的command对象。当假设所传输的数据是一个 Object[]时,可以用这种方式传输。结合unionmon中的代码生成机制,每个vo的序列化/反序列化方法可以在代码生成过程中完成。同样地,vox的序列化/反序列化方法需要手写。
参考代码:附录中的test3.XmlRPCSerializable , test3.AccountVO , test3.XmlRPCClient , test3.JavaServer让tomcat支持rpc server 做法:1.实现一个Servlet,并配置到tomcat中;2.让rpc client直接找这个servlet,获得服务。
注意rpc client使用的是http post方法,所以该servlet中只需要实现doPost方法。
过程:在tomcat中的web.xml增加如下配置:
<servlet>
<servlet-name>SampleServiceServlet</servlet-name>
<servlet-class>test4.ServletXmlRPCServer</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SampleServiceServlet</servlet-name>
<url-pattern>/SampleServiceServlet</url-pattern>
</servlet-mapping>
参考类:附件中的test4.SampleService,test4.ServletXmlRPCServer,test4.XmlRPCClient

6相关信息编辑

3.1.能否通过introspect方式,使得自定义类型的vo的序列化/反序列化工作自动完成.castor可以完成对象的xml binding,似乎可参考
3.2.soap协议比xmlrpc复杂并强大。soap不熟悉。另,soap一定与web service在一起用?能否不用web service,但使用soap做rmi的协议。

7例子编辑

2.0.环境准备:下载如下包并设置到CLASSPATH
apache xmlrpc软件包
commons-httpclient-3.0-rc4.jar
commons-codec-1.3.jar

8中文版编辑

本规范说明的XML-RPC协议实现UserLand Frontier5.1。
关于非技术性说明,请访问XML-RPC for Newbies。
文档提供了实现XML-RPC所需要的所有信息。
前言
XML-RPC是一种基于Internet的远程函数调用协议。
XML-RPC消息都是HTTP-POST请求。请求的主要部分的XML。服务器端执行后的返回结果同样也是XML格式
函数调用的参数可以是scalars, numbers, strings, dates等等;也可以是混合型的记录和结构体。
Request请求样式
关于请求头
第一行的URI格式不是特定的。可以为空,如果服务器只处理XML-RPC请求甚至可以只是简单的一个斜线。可是,如果服务器除了XML-RPC外还提供其他的HTTP请求,URI可以帮助我们把请求指向特定的XML-RPC服务。
User-Agent和Host项是必须的。
Content-Type的值必须是text/xml.
Content-Length必须指定,而且必须是正确的值。
有效的格式
XML-RPC具有和XML一样的有效格式,并且是一个<methodCall>结构。
<methodCall>必须包含一个值为字符型的<methodName>子元素,用来表明被调用的方法。这个字符必须符合以下规定:大小写字母、数字0-9、下划线、点、冒号和斜线。至于怎么解释这个字符串将有服务器端来决定。
Scalar <value>s <value>
<value>值被嵌入类型标签中,支持的类型如下表:
Tag
Type
Example
<i4> or <int>
four-byte signed integer
-12
<boolean>
0 (false) or 1 (true)
1
<string>
string
hello world
<double>
double-precision signed floating point number
-12.214
<dateTime.iso8601>
date/time
19980717T14:08:55
<base64>
base64-encoded binary
eW91IGNhbid0IHJlYWQgdGhpcyE=
如果没有指定类型,默认为字符串。
<struct>s
参数值可以是<struct>。
每个<struct>包含若干<member>,每个<member>包含一个<name>和一个<value>.
如果所示为包含两个值的<struct>
<struct>是可以递归使用的,任何<value>都里还可以<struct>或其他任何类型,包括后面将要说明的<array>。
<array>s
值可以个<array>
一个<array>简单的有一个<data>元素。<data>可以是任何合法类型。
下面是一个有4个值的array:
<array> <data> <value><i4>12</i4></value> <value><string>Egypt</string></value> <value><boolean>0</boolean></value> <value><i4>-31</i4></value> </data> </array>
<array> elements do not have names.
<array> 元素没有名字。
你可以混合使用上面列出的几种类型。
<arrays>可以递归使用,其值可以是<array>或其他类型,包括上面说明的<strut>。
Response应答样式
下面是一个 XML-RPC请求:
HTTP/1.1 200 OK Connection: close Content-Length: 158 Content-Type: text/xml Date: Fri, 17 Jul 1998 19:55:08 GMT Server: UserLand Frontier/5.1.2-WinNT <?xml version="1.0"?> <methodResponse> <params> <param> <value><string>South Dakota</string></value> </param> </params> </methodResponse>
Respnse应答格式
除非底层操作出现错,否则总是返回200 OK.
Content-Type是text/xml。必须设置Content-Length,并且必须是正确的值。
应到内容是一个简单的XML,可是是<methodResponse>包含一个<params>,<params>包含一个<param>,<param>包含一个<value>。
<methodResponse>可能含有一个< fault>标签。<fault>的值为<struct>类型,<struct>有两个元素,值为< int>的<faultCode>和值为<string>的<faultString>。
<methodResponse>不能既有<fault>又有<params>。
Fault example
HTTP/1.1 200 OK Connection: close Content-Length: 426 Content-Type: text/xml Date: Fri, 17 Jul 1998 19:55:02 GMT Server: UserLand Frontier/5.1.2-WinNT <?xml version="1.0"?> <methodResponse> <fault> <value> <struct> <member> <name>faultCode</name> <value><int>4</int></value> </member> <member> <name>faultString</name> <value><string>Too many parameters.</string></value> </member> </struct> </value> </fault> </methodResponse>
Strategies/Goals
Firewalls. The goal of this protocol is to lay a compatible foundation across different environments, no new power is provided beyond the capabilities of the CGI interface. Firewall software can watch for POSTs whose Content-Type is text/xml.
Discoverability. We wanted a clean, extensible format that's very simple. It should be possible for an HTML coder to be able to look at a file containing an XML-RPC procedure call, understand what it's doing, and be able to modify it and have it work on the first or second try.
Easy to implement. We also wanted it to be an easy to implement protocol that could quickly be adapted to run in other environments or on other operating systems.
Updated 1/21/99 DW
The following questions came up on the UserLanddiscussion groupas XML-RPC was being implemented in Python.
The Response Format section says "The body of the response is a single XML structure, a <methodResponse>, which can contain a single <params>..." This is confusing. Can we leave out the <params>?
No you cannot leave it out if the procedure executed successfully. There are only two options, either a response contains a <params> structure or it contains a <fault> structure. That's why we used the word "can" in that sentence.
Is "boolean" a distinct data type, or can boolean values be interchanged with integers (e.g. zero=false, non-zero=true)?
Yes, boolean is a distinct data type. Some languages/environments allow for an easy coercion from zero to false and one to true, but if you mean true, send a boolean type with the value true, so your intent can't possibly be misunderstood.
What is the legal syntax (and range) for integers? How to deal with leading zeros? Is a leading plus sign allowed? How to deal with whitespace?
An integer is a 32-bit signed number. You can include a plus or minus at the beginning of a string of numeric characters. Leading zeros are collapsed. Whitespace is not permitted. Just numeric characters preceeded by a plus or minus.
What is the legal syntax (and range) for floating point values (doubles)? How is the exponent represented? How to deal with whitespace? Can infinity and "not a number" be represented?
There is no representation for infinity or negative infinity or "not a number". At this time, only decimal point notation is allowed, a plus or a minus, followed by any number of numeric characters, followed by a period and any number of numeric characters. Whitespace is not allowed. The range of allowable values is implementation-dependent, is not specified.
What characters are allowed in strings? Non-printable characters? Null characters? Can a "string" be used to hold an arbitrary chunk of binary data?
Any characters are allowed in a string except < and &, which are encoded as &lt; and &amp;. A string can be used to encode binary data.
Does the "struct" element keep the order of keys. Or in other words, is the struct "foo=1, bar=2" equivalent to "bar=2, foo=1" or not?
The struct element does not preserve the order of the keys. The two structs are equivalent.
Can the <fault> struct contain other members than <faultCode> and <faultString>? Is there a global list of faultCodes? (so they can be mapped to distinct exceptions for languages like Python and Java)?
A <fault> struct may not contain members other than those specified. This is true for all other structures. We believe the specification is flexible enough so that all reasonable data-transfer needs can be accomodated within the specified structures. If you believe strongly that this is not true, please post a message on the discussion group.
There is no global list of fault codes. It is up to the server implementer, or higher-level standards to specify fault codes.
What timezone should be assumed for the dateTime.iso8601 type? UTC? localtime?
Don't assume a timezone. It should be specified by the server in its documentation what assumptions it makes about timezones.
Additions
<base64> type. 1/21/99 DW.
Updated 6/30/03 DW
Removed "ASCII" from definition of string.
Changed copyright dates, below, to 1999-2003 from 1998-99.
Copyright and disclaimer
? Copyright 1998-2003 UserLand Software. All Rights Reserved.
This document and translations of it may be copied and furnished to others, and derivative works that comment on or otherwise explain it or assist in its implementation may be prepared, copied, published and distributed, in whole or in part, without restriction of any kind, provided that the above copyright notice and these paragraphs are included on all such copies and derivative works.
This document may not be modified in any way, such as by removing the copyright notice or references to UserLand or other organizations. Further, while these copyright restrictions apply to the written XML-RPC specification, no claim of ownership is made by UserLand to the protocol it describes. Any party may, for commercial or non-commercial purposes, implement this protocol without royalty or license fee to UserLand. The limited permissions granted herein are perpetual and will not be revoked by UserLand or its successors or assigns.
This document and the information contained herein is provided on an "AS IS" basis and USERLAND DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE

xmlrpc的更多相关文章

  1. XmlRpc.net 入参结构体嵌套的转义操作

    项目使用C#开发,需要使用XmlRpc和Linux服务器端交互,用的是XmlRpc.net. 普通的程序调用入参和出差都没有问题,今天遇到入参结构体嵌套,结果 args 入参在服务器端不能解析.抓包数 ...

  2. jmeter(三)Sample之SOAP/XML-RPC Request

    项目背景:公司的微信端H5界面新开发了会员注册功能,需要对其进行压力测试 项目目标:需要承受每分钟最少6000的压力 一.建立一个测试计划(test plan) 之前有说过,jmeter打开后会自动生 ...

  3. xmlrpc实现bugzilla api调用(无会话保持功能,单一接口请求)

    xmlrpc实现bugzilla4   xmlrpc api调用(无会话保持功能,单一接口请求),如需会话保持,请参考我的另外一篇随笔(bugzilla4的xmlrpc接口api调用实现分享: xml ...

  4. Python与PHP通过XMLRPC进行通信

    Python与PHP通过XMLRPC进行通信:服务器端用Python,客户端用PHP. 服务器端:xmlrpc_server.py #!/usr/bin/python # coding: UTF-8 ...

  5. Jmeter组件6. SOAP/XML-RPC Request

    Jmeter测试SOAP的web services现在有两种方式 第一是使用SOAP/XML-RPC Request组件,第二使用HTTP Request组件 Send SOAPACtion, 同ht ...

  6. XML-RPC远程方法调用

    一.简介 XML-RPC的全称是XML Remote Procedure Call,即XML远程方法调用. 它是一套允许运行在不同操作系统.不同环境的程序实现基于Internet过程调用的规范和一系列 ...

  7. 利用MetaWeblog API实现XMLRPC写博客功能

    Windows Live Writer是一款小巧的写博客的工具,非常方便,甚至网上看到过有的评论称Live Writer是一款最不像微软产品的微软产品. Writer支持MSN Spaces以及Wor ...

  8. odoo XMLRPC 新库 OdooRPC 尝鲜

    无意中发现了python居然有了OdoRPC的库,惊喜之下赶紧尝试一番,比XMLRPC简洁了不少,机制看样子是利用的JsonRPC. #原文出自KevinKong的博客http://www.cnblo ...

  9. bugzilla4的xmlrpc接口api调用实现分享: xmlrpc + https + cookies + httpclient +bugzilla + java实现加密通信下的xmlrpc接口调用并解决登陆保持会话功能

    xmlrpc .  https . cookies . httpclient.bugzilla . java实现加密通信下的xmlrpc接口调用并解决登陆保持会话功能,网上针对bugzilla的实现很 ...

  10. 防止WordPress利用xmlrpc.php进行暴力破解以及DDoS

    早在2012 年 12 月 17 日一些采用 PHP 的知名博客程序 WordPress被曝光存在严重的漏洞,该漏洞覆盖WordPress 全部已发布的版本(包括WordPress 3.8.1).该漏 ...

随机推荐

  1. 【Unity Shaders】游戏性和画面特效——创建一个夜视效果的画面特效

    本系列主要参考<Unity Shaders and Effects Cookbook>一书(感谢原书作者),同时会加上一点个人理解或拓展. 这里是本书所有的插图.这里是本书所需的代码和资源 ...

  2. Git Bash+EGit在项目中配合使用最常用方法总结(根据场景使用)

    最近在项目中使用Git进行代码管理,之前一直用SVN进行管理,现在谈一谈Git在项目中如何与EGit插件配合使用,高效同步开发. 使用过SVN一段时间的人,初识Git一定感觉很别扭,发现会遇到各种各样 ...

  3. GrabCut in One Cut(基于图割算法grabcut的一次快速图像分割的OpenCV实现)----目前效果最好的图割

     One cut in grabcut(grabcut算法的非迭代实现?) 本文针对交互式图像分割中的图割算法,主要想翻译一篇英文文献.不足之处请大家指正. 这是博主近期看到的效果最好,实现最简单 ...

  4. iOS 图片裁剪与修改

    最近做的项目中需要上传头像,发表内容的时候也要涉及到图片上传,我直接用的原图上传,但是由于公司网络差,原图太大,老是加载好久好久,所以需要把原图裁剪或者修改分辨率之后再上传,找了好久,做了很多尝试才解 ...

  5. C++之多态性与虚函数

    面向对象程序设计中的多态性是指向不同的对象发送同一个消息,不同对象对应同一消息产生不同行为.在程序中消息就是调用函数,不同的行为就是指不同的实现方法,即执行不同的函数体.也可以这样说就是实现了&quo ...

  6. React Native入门教程2 -- 基本组件使用及样式

    在上一篇文章中,我们学会了如何搭建React Native的环境(React Native入门教程(笔记) 1 – 开发环境搭建),不知道你们是否搭建好了呢,如果还没有,那么快动起小手,来体验RN带给 ...

  7. UNIX环境高级编程——计算机体系结构基础知识

    无论是在CPU外部接总线的设备还是在CPU内部接总线的设备都有各自的地址范围,都可以像访问内存一样访问,很多体系结构(比如ARM)采用这种方式操作设备,称为等都会产生异常. 通常操作系统把虚拟地址空间 ...

  8. Windows下配置nginx+FastCgi + Spawn-fcgi

    前提: 下载nginx, FastCgi, Spawn-fcgi Spawn-fcgi有个Windows的版本,但不能在VS中编译,这里有一个编译好的版本:http://download.csdn.n ...

  9. 【一天一道LeetCode】#72. Edit Distance

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given t ...

  10. 用CSS指定外部链接的样式

    大部分的信息类网站,比如维基百科,都会对外部链接(<a>标签)指定特定的样式.作为用户,一眼就知道该链接是指向另一个站点的资源是很好的体验.许多网站在服务器端做外部链接检查,添加一个`re ...