`
yuanfen860913
  • 浏览: 115668 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
文章分类
社区版块
存档分类
最新评论
阅读更多

XML-RPC

  一 什么是XML-RPC   XML-RPC的全称是XML Remote Procedure Call,即XML远程方法调用。   它是一套允许运行在不同操作系统、不同环境的程序实现基于Internet过程调用的规范和一系列的实现。   这种远程过程调用使用http作为传输协议,XML作为传送信息的编码格式。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   <?xml version="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   <?xml version="1.0"?>   <methodResponse>   <params>   <param>   <value><string>South Dakota</string></value>   </param>   </params>   </methodResponse>   二 XML-RPC入门程序   以下的入门程序包括一个管理器(HelloHandler)、一个服务器(HelloServer)、一个客户程序(HelloClient)。   首先要做的是创建用于远程过程调用的类和方法,人们常常称之为管理器。Xml-rpc管理器是一个方法和方法集,它接受xml-rpc请求,并对请求的内容进行解码,再向一个类和方法发出请求。   //管理器类   package xmlRpc;   /**   * @author trier   *   * <b><code>HelloHandler</code></b> is a simple handler than can   * be registered with an XML-RPC server   */   public class HelloHandler {   public String sayHello(String name){   return "Hello " + name;   }   }   服务器程序将创建的管理器注册到服务器上,并为服务器指明应用程序其他特定的参数。   //服务器类   package xmlRpc;   /**   *   * <b><code>HelloServer</code></b> is a simple XML-RPC server   * that will take the <code>HelloHandler</code> class available   * for XML-PRC calls.   * <o:p   */   import org.apache.xmlrpc.WebServer;   import org.apache.xmlrpc.XmlRpc;   import java.io.IOException;   public class HelloServer {   public static void main(String[] args){   if(args.length<1){   System.out.println("Usage: java HelloServer [port]");   System.exit(-1);   }   try{   XmlRpc.setDriver("org.apache.xerces.parsers.SAXParser");   //start the server   System.out.println("Starting XML-RPC Server......");   WebServer server = new WebServer(Integer.parseInt(args[0]));   //register our handler class   server.addHandler("hello",new HelloHandler());   System.out.println("Now accepting requests......");   }catch(ClassNotFoundException e){   System.out.println("Could not locate SAX Driver");   }catch(IOException e){   System.out.println("Could not start server: "+e.getMessage());   }   }   }   //客户程序   package xmlRpc;   /**   *   * <b><code>HelloClient</code></b> is a simple XML-RPC client   * that makes an XML-RPC request to <code>HelloServer</code>   */   import java.io.IOException;   import java.util.Vector;   import org.apache.xmlrpc.XmlRpc;   import org.apache.xmlrpc.XmlRpcClient;   import java.net.MalformedURLException;   import org.apache.xmlrpc.XmlRpcException;   public class HelloClient {   public static void main(String[] args){   if(args.length<1){   System.out.println("Usage: java HelloClient [your name]");   System.exit(-1);   }   try{   //Use the Apache Xereces SAX Driver   XmlRpc.setDriver("org.apache.xerces.parsers.SAXParser");   //Specify the server   XmlRpcClient client = new XmlRpcClient("http://localhost:8585");   //create request   Vector params = new Vector();   params.addElement(args[0]);   //make a request and print the result   String result = (String)client.execute("hello.sayHello",params);   System.out.println("Response from server: "+ result);   }catch(ClassNotFoundException e){   System.out.println("Could not locate SAX Driver");   }catch(MalformedURLException e){   System.out.println("Incorrect URL fro xml-rpc server foramt:"+e.getMessage());   }catch(XmlRpcException e){   System.out.println("XmlRpcException :"+e.getMessage());   }catch(IOException e){   System.out.println("IOException:"+e.getMessage());   }   }   }   三 RPC和RMI的简单比较   在RMI和RPC之间最主要的区别在于方法是如何别调用的。在RMI中,远程接口使每个远程方法都具有方法签名。如果一个方法在服务器上执行,但是没有相匹配的签名被添加到这个远程接口上,那么这个新方法就不能被RMI客户方所调用。在RPC中,当一个请求到达RPC服务器时,这个请求就包含了一个参数集和一个文本值,通常形成“classname.methodname”的形式。这就向RPC服务器表明,被请求的方法在为“classname”的类中,名叫“methodname”。然后RPC服务器就去搜索与之相匹配的类和方法,并把它作为那种方法参数类型的输入。这里的参数类型是与RPC请求中的类型是匹配的。一旦匹配成功,这个方法就被调用了,其结果被编码后返回客户方。   </o:p>
分享到:
评论

相关推荐

    xml-rpc学习心得

    xml-rpc 学习心得是我自己的学习心得体会。

    3.0 XML-RPC 官方示例+源码+官网地址资料.rar

    3.0 XML-RPC

    Apache xml-rpc入门

    Apache xml-rpc入门详细的描述xmlrpc的开发过程,并带有例子。

    XML-RPC客户端程序

    XML-RPC客户端测试程序 向XMLRPC服务器发送一个XML-RPC请求,以文本文件读取xml文件; 记录返回的数据到文件中; windows命令行程序,使用前请配置*.pln文件 askcyg@hotmail.com

    php xml-rpc 协议 非常有用哦

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

    xml-rpc.net.2.4.0.zip

    Version 2.4.0 has been released: xml-rpc.net.2.4.0.zip New feature and fixed issues: New StructParams property on XmlRpcMethodAttribute which provides supports for APIs which use a struct to ...

    LabVIEW XML-RPC

    LabVIEW 版 XML_RPC,有7.1,8.0,8.5三个版本。

    XML-RPC.rar_HTTP协议_XML-R_XML-RPC _xml rpc

    简单介绍了XML-RPC这种通过HTTP协议进行RPC通信的规范。 以Apache XML-RPC 3.0为基础,对XML-RPC的基本原理及Apache XML-RPC 3.0的主要特性进行了讨论和分析

    使用 XML-RPC 为 C++ 应用程序启用 Web 服务

    简单对象访问协议(Simple Object Access Protocol,SOAP)、代表性状态传输(Representational State Transfer,REST)以及 XML 远程过程调用协议(XML Remote Procedure Call,XML-RPC)等 Web 服务协议可帮助将...

    XML-RPC.rar_python xml rpc_python写xml_xml rpc_xml-rpc python

    我自己动手写的XML-RPC,最近自己写了写关于大规模分布式只是学习的实验,其中用到了python里面的清凉级

    apache XML-RPC 实现

    commons-logging-1.1.jar ws-commons-util-1.0.2.jar xmlrpc-client-3.1.3.jar xmlrpc-common-3.1.3.jar xmlrpc-server-3.1.3.jar

    xml-rpc协议资料

    xml-rpc 是一套规范及其一系列的实现,允许运行在不同操作系统、不同环境的程序基于internet进行远程过程调用。  这种远程过程调用使用http作为传输协议,xml作为传送信息的编码格式。Xml-Rpc的定义尽可能的保持了...

    xml-rpc.net.3.0

    xml-rpc.net.3.0.0.270-snapshot,用于c#访问解析XML-RPC

    Java RPC通信机制之XML-RPC

    Java RPC通信机制之XML-RPC

    解决Delphi XML-RPC 中文乱码

    此资源不要下载,请下载最新的 最近要用XML-RPC机制实现...下载Delphi XML-RPC 后发现中文字符串会出现乱码,跟踪代码后发现XML-RPC默认的 字符编码是UTF-8,而且QT也都是用UTF-8编程,故把传输字符串改为UTF-8就行了,

    Delphi XML-RPC 中文乱码解决方法

    最近要用XML-RPC机制实现delphi程序与Qt程序之间的通信,从开源网站http://sourceforge.net/projects/delphixml-rpc/下载Delphi XML-RPC 后发现中文字符串会出现乱码,跟踪代码后发现XML-RPC默认的字符编码是UTF-8,...

    解决Delphi XML-RPC 中文乱码、结构/数组等没有解析I4项BUG

    最近要用XML-RPC机制实现delphi程序与Qt程序之间的通信,从...下载Delphi XML-RPC 后发现中文字符串会出现乱码,跟踪代码后发现XML-RPC默认的 字符编码是UTF-8,而且QT也都是用UTF-8编程,故把传输字符串改为UTF-8就行了。

    apache XML-RPC

    apache XML-RPC,开发所需5个jarapache XML-RPC,开发所需5个jar

    Apache的XML-RPC简化你的WebService应用

    NULL 博文链接:https://x7700.iteye.com/blog/1186416

Global site tag (gtag.js) - Google Analytics