XML-RPC是一个远程过程调用远端程序呼叫)(remote procedure call,RPC)的分布式计算协议,通过XML将调用函数封装,并使用HTTP协议作为传送机制。
 
中文名
XML-RPC
外文名
XML Remote Procedure Call
属    于
标准通用标记语言
类    型
一个子集

关于XML-RPC

基本介绍

XML-RPC是工作在Internet上的远程过程调用协议。一个XML-RPC消息就是一个请求体为xml的http-post请求,被调用的方法在服务器端执行并将执行结果以xml格式编码后返回。

Request example

Here's an example of an XML-RPC request:
POST /RPC2 HTTP/1.0User-Agent: Frontier/5.1.2 (WinNT)Host: betty.userland.comContent-Type: text/xmlContent-length: 181
1
2
3
4
5
6
7
8
9
10
11
<?xmlversion="1.0"?>
<methodCall>
<methodName>examples.getStateName</methodName>
<params>
<param>
<value>
<i4>41</i4>
</value>
</param>
</params>
</methodCall>

Response example

Here's an example of a response to an XML-RPC request:
HTTP/1.1 200 OKConnection: closeContent-Length: 158Content-Type: text/xmlDate: Fri, 17 Jul 1998 19:55:08 GMTServer: UserLand Frontier/5.1.2-WinNT
1
2
3
4
5
6
7
8
9
10
11
12
<?xmlversion="1.0"?>
<methodResponse>
<params>
<param>
<value>
<string>
SouthDakota
</string>
</value>
</param>
</params>
</methodResponse>

XML-RPC入门程序

基本做法

以下的入门程序包括一个管理器(HelloHandler)、一个服务器(HelloServer)、一个客户程序(HelloClient)。
首先要做的是创建用于远程过程调用的类和方法,人们常常称之为管理器。Xml-rpc管理器是一个方法和方法集,它接受xml-rpc请求,并对请求的内容进行解码,再向一个类和方法发出请求。
 

管理器类

 
1
2
3
4
5
6
7
packagexmlRpc;
/***@authortrier**<b><code>HelloHandler</code></b>isasimplehandlerthancan*beregisteredwithanXML-RPCserver*/
publicclassHelloHandler{
publicStringsayHello(Stringname){
return"Hello"+name;
}
}
服务器程序将创建的管理器注册到服务器上,并为服务器指明应用程序其他特定的参数。
 

服务器类

 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
packagexmlRpc;
/**
*
*<b><code>HelloServer</code></b>isasimpleXML-RPCserver
*thatwilltakethe<code>HelloHandler</code>classavailable
*forXML-PRCcalls.
*<o:p
*/
importorg.apache.xmlrpc.WebServer;
importorg.apache.xmlrpc.XmlRpc;
importjava.IOException;
publicclassHelloServer{
publicstaticvoidmain(String[]args){
if(args.length<1){
System.out.println("Usage:javaHelloServer[port]");
System.exit(-1);
}
try{
XmlRpc.setDriver("org.apache.xerces.parsers.SAXParser");
//starttheserver
System.out.println("StartingXML-RPCServer......");
WebServerserver=newWebServer(Integer.parseInt(args[0]));
//registerourhandlerclass
server.addHandler("hello",newHelloHandler());
System.out.println("Nowacceptingrequests......");
}catch(ClassNotFoundExceptione){
System.out.println("CouldnotlocateSAXDriver");
}catch(IOExceptione){
System.out.println("Couldnotstartserver:"+e.getMessage());
}
}
}
 

客户程序

 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
packagexmlRpc;
/**
*
*<b><code>HelloClient</code></b>isasimpleXML-RPCclient
*thatmakesanXML-RPCrequestto<code>HelloServer</code>
*/
importjava.i.IOException;
importjava.util.Vector;
importorg.apache.xmlrpc.XmlRpc;
importorg.apache.xmlrpc.XmlRpcClient;
importjava.t.MalformedURLException;
importorg.apache.xmlrpc.XmlRpcException;
publicclassHelloClient{
publicstaticvoidmain(String[]args){
if(args.length<1){
System.out.println("Usage:javaHelloClient[yourname]");
System.exit(-1);
}
try{
//UsetheApacheXerecesSAXDriver
XmlRpc.setDriver("org.apache.xerces.parsers.SAXParser");
//Specifytheserver
XmlRpcClientclient=newXmlRpcClient("http://localhost:8585");
//createrequest
Vectorparams=newVector();
params.addElement(args[0]);
//makearequestandprinttheresult
Stringresult=(String)client.execute("hello.sayHello",params);
System.out.println("Responsefromserver:"+result);
}catch(ClassNotFoundExceptione){
System.out.println("CouldnotlocateSAXDriver");
}catch(MalformedURLExceptione){
System.out.println("IncorrectURLfroxml-rpcserverforamt:"+e.getMessage());
}catch(XmlRpcExceptione){
System.out.println("XmlRpcException:"+e.getMessage());
}catch(IOExceptione){
System.out.println("IOException:"+e.getMessage());
}
}
}
 

RPC和RMI的简单比较

调用形式

在RMI和RPC之间最主要的区别在于方法是如何被调用的。在RMI中,远程接口使每个远程方法都具有方法签名。如果一个方法在服务器上执行,但是没有相匹配的签名被添加到这个远程接口上,那么这个新方法就不能被RMI客户方所调用。
 

classname.methodname的形式

在RPC中,当一个请求到达RPC服务器时,这个请求就包含了一个参数集和一个文本值,通常形成“classname.methodname”的形式。
 

methodname

这就向RPC服务器表明,被请求的方法在为“classname”的类中,名叫“methodname”。然后RPC服务器就去搜索与之相匹配的类和方法,并把它作为那种方法参数类型的输入。这里的参数类型是与RPC请求中的类型是匹配的。
 

匹配成功后

一旦匹配成功,这个方法就被调用了,其结果被编码后返回客户方。 

XML-RPC-1概述的更多相关文章

  1. 什么是XML RPC?

    # -*- coding: cp936 -*- #python 27 #xiaodeng #什么是XML RPC? #中文叫:远程过程调用 #使用http协议做传输协议的rpc机制,使用xml文本的方 ...

  2. The type javax.xml.rpc.ServiceException cannot be resolved.It is indirectly

    The type javax.xml.rpc.ServiceException cannot be resolved.It is indirectly 博客分类: 解决方案_Java   问题描述:T ...

  3. 【PHP XML与dtd概述【完整版】】

    一.XML文件简介 关于XML的大多数人都知道一些,HTML->xhtml->xml,这个顺序本来应当是HTML发展的顺序. XML可以当做配置文件使用,还可以充当小型的数据库. vers ...

  4. 关于XML的DTD概述

    1 DTD概述 1.1 什么是DTD DTD(Document Type Definition),文档类型定义,用来约束XML文档.或者可以把DTD理解为创建XML文档的结构!例如可以用DTD要求XM ...

  5. xml rpc SimpleXMLRPCServer [python]

    SimpleXMLRPCServe 其实里面xml的概念不是很强,主要是rpc !不用关心什么xml . rpc 是就是远程调用,把函数什么的放到远程服务器上,本地调用就行了.用 SimpleXMLR ...

  6. [03] mapper.xml的基本元素概述

    1.select 我们基于这个持久层接口 GirlDao: public interface GirlDao { List<Girl> findByAge(int age); Girl f ...

  7. alluxio源码解析-rpc调用概述(1)

    alluxio中几种角色以及角色之间的rpc调用: 作为分布式架构的文件缓存系统,rpc调用必不可少 client作为客户端 master提供thrift rpc的服务,管理以下信息: block信息 ...

  8. xml的解析(概述)

    使用java解析xml☆☆☆ 四个类:分别是针对dom和sax解析使用的类   -dom :     DocumentBuilder:解析器类       -这个类是个抽象类,不能new,       ...

  9. Android之布局androidmanifest.xml 资源清单 概述

    转载:https://www.cnblogs.com/wytings/p/4083463.html AndroidManifest.xml配置文件对于Android应用开发来说是比较细但又很重要的基础 ...

  10. supervisord支持扩展(xml RPC API & Third Party Applications and Libraries)

    XML-RPC API Documentation http://www.supervisord.org/api.html Third Party Applications and Libraries ...

随机推荐

  1. Greenwich.SR2版本的Spring Cloud Zipkin实例

    调用链跟踪是微服务架构中的基础能力,Spring Cloud Zipkin+Sleuth为我们提供了该能力.首先我们先建立Zipkin服务端,它需要集成Eureka,用于发现服务提供方和消费方,进行数 ...

  2. 安装mycat

    1.下载mycat 为了方便,我已经下载下来.我选择的版本是1.6版本 2.解压,安装在/home/xm6f/dev目录下 cd /home/xm6f/devtar -zxvf Mycat-serve ...

  3. Django使用request和response对象

    当请求一张页面时,Django把请求的metadata数据包装成一个HttpRequest对象,然后Django加载合适的view方法,把这个HttpRequest 对象作为第一个参数传给view方法 ...

  4. C# winform中使用Panel调节窗口变化是各控件的位置(转)

    我的目的是在窗口上有些控件,在窗口大小变化时,上面的控件位置不动,大小也不动.下面的控件随着窗口的大小变化而变大. 做法是用两个panel,panelTop和panelFill.上面的控件都放到pan ...

  5. 原装win8系统电脑崩溃问题解决

    原装win8系统电脑崩溃问题解决 声明:引用请注明出处http://blog.csdn.net/lg1259156776/ 说明:之所以撰写本篇关于win8原装系统电脑崩溃的博文,一是要吐槽一下原装w ...

  6. php 阿里云国内短信实例

    调用:先去阿里云申请短信服务 $smsArr = array( "accessKeyId" => "", // key "accessKeySe ...

  7. 移动架构-json解析框架

    JSON在现在数据传输中占据着重要地位,相比于xml,其解析和构成都要简单很多,第三方的解析框架也不胜枚举,这里之所以要自定义一个json解析框架,一方面是更好的了解json解析过程,另一方面是有时候 ...

  8. Net中实现HTML生成图片或PDF

    Net中实现HTML生成图片或PDF的几种方式 前段时间由于项目上的需求,要在.Net平台下实现把HTML内容生成图片或PDF文件的功能,特意在网上研究了几种方案,这里记录一下以备日后再次使用.当时想 ...

  9. matplotlib中的imshow()

    import matplotlib.pyplot as plt plt.imshow(x,cmap) x表示要显示的图片变量,cmap为颜色图谱,默认为RGB(A)颜色空间,也可以指定,gray是灰度 ...

  10. 学习笔记:oracle学习二:oracle11g数据库sql*plus命令之常用sqlplus命令、格式化查询结果

    目录 1.常用sqlplus命令 1.1 HELP命令 1.2 describe命令 1.3 SPOOL命令 1.4 其他常用命令 1.4.1 define命令 1.4.2 show命令 1.4.3 ...