XML-RPC-1概述

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请求中的类型是匹配的。
 

匹配成功后

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

转载于:https://www.cnblogs.com/hmit/p/11399696.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
智慧校园的建设目标是通过数据整合、全面共享,实现校园内教学、科研、管理、服务流程的数字化、信息化、智能化和多媒体化,以提高资源利用率和管理效率,确保校园安全。 智慧校园的建设思路包括构建统一支撑平台、建立完善管理体系、大数据辅助决策和建设校园智慧环境。通过云架构的数据中心与智慧的学习、办公环境,实现日常教学活动、资源建设情况、学业水平情况的全面统计和分析,为决策提供辅助。此外,智慧校园还涵盖了多媒体教学、智慧录播、电子图书馆、VR教室等多种教学模式,以及校园网络、智慧班牌、校园广播等教务管理功能,旨在提升教学品质和管理水平。 智慧校园的详细方案设计进一步细化了教学、教务、安防和运维等多个方面的应用。例如,在智慧教学领域,通过多媒体教学、智慧录播、电子图书馆等技术,实现教学资源的共享和教学模式的创新。在智慧教务方面,校园网络、考场监控、智慧班牌等系统为校园管理提供了便捷和高效。智慧安防系统包括视频监控、一键报警、阳光厨房等,确保校园安全。智慧运维则通过综合管理平台、设备管理、能效管理和资产管理,实现校园设施的智能化管理。 智慧校园的优势和价值体现在个性化互动的智慧教学、协同高效的校园管理、无处不在的校园学习、全面感知的校园环境和轻松便捷的校园生活等方面。通过智慧校园的建设,可以促进教育资源的均衡化,提高教育质量和管理效率,同时保障校园安全和提升师生的学习体验。 总之,智慧校园解决方案通过整合现代信息技术,如云计算、大数据、物联网和人工智能,为教育行业带来了革命性的变革。它不仅提高了教育的质量和效率,还为师生创造了一个更加安全、便捷和富有智慧的学习与生活环境。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值