<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Knight of the round table

    wansong

    Webservice - XML-RPC

    http://baike.baidu.com/view/643379.htm


    XML-RPC的全稱是XML Remote Procedure Call,即XML遠(yuǎn)程方法調(diào)用。
      它是一套允許運行在不同操作系統(tǒng)、不同環(huán)境的程序?qū)崿F(xiàn)基于Internet過程調(diào)用的規(guī)范和一系列的實現(xiàn)。
      這種遠(yuǎn)程過程調(diào)用使用http作為傳輸協(xié)議,XML作為傳送信息的編碼格式。Xml-Rpc的定義盡可能的保持了簡單,但同時能夠傳送、處理、返回復(fù)雜的數(shù)據(jù)結(jié)構(gòu)。
      XML-RPC是工作在Internet上的遠(yuǎn)程過程調(diào)用協(xié)議。一個XML-RPC消息就是一個請求體為xml的http-post請求,被調(diào)用的方法在服務(wù)器端執(zhí)行并將執(zhí)行結(jié)果以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)、一個服務(wù)器(HelloServer)、一個客戶程序(HelloClient)。
      首先要做的是創(chuàng)建用于遠(yuǎn)程過程調(diào)用的類和方法,人們常常稱之為管理器。Xml-rpc管理器是一個方法和方法集,它接受xml-rpc請求,并對請求的內(nèi)容進(jìn)行解碼,再向一個類和方法發(fā)出請求。
      //管理器類
      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;
      }
      }
      服務(wù)器程序?qū)?chuàng)建的管理器注冊到服務(wù)器上,并為服務(wù)器指明應(yīng)用程序其他特定的參數(shù)。
      //服務(wù)器類
      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之間最主要的區(qū)別在于方法是如何別調(diào)用的。在RMI中,遠(yuǎn)程接口使每個遠(yuǎn)程方法都具有方法簽名。如果一個方法在服務(wù)器上執(zhí)行,但是沒有相匹配的簽名被添加到這個遠(yuǎn)程接口上,那么這個新方法就不能被RMI客戶方所調(diào)用。在RPC中,當(dāng)一個請求到達(dá)RPC服務(wù)器時,這個請求就包含了一個參數(shù)集和一個文本值,通常形成“classname.methodname”的形式。這就向RPC服務(wù)器表明,被請求的方法在為“classname”的類中,名叫“methodname”。然后RPC服務(wù)器就去搜索與之相匹配的類和方法,并把它作為那種方法參數(shù)類型的輸入。這里的參數(shù)類型是與RPC請求中的類型是匹配的。一旦匹配成功,這個方法就被調(diào)用了,其結(jié)果被編碼后返回客戶方。

    posted on 2011-01-05 11:23 w@ns0ng 閱讀(525) 評論(0)  編輯  收藏 所屬分類: J2EE 、web service

    主站蜘蛛池模板: 国产L精品国产亚洲区久久| 日本一区二区免费看| 亚洲毛片不卡av在线播放一区| 久久久久精品国产亚洲AV无码| 亚洲精品免费在线视频| 亚洲精品在线播放| 最近中文字幕大全中文字幕免费| 亚洲精品视频在线观看免费| 亚洲一级毛片免费在线观看| 国产美女无遮挡免费网站| 久久久久亚洲AV无码专区桃色| 一级人做人a爰免费视频| 亚洲无码视频在线| 你懂的网址免费国产| 麻豆亚洲AV永久无码精品久久| 亚洲最大福利视频| 青青草国产免费久久久91| 亚洲AV成人一区二区三区AV| 亚洲精品免费在线观看| 亚洲中文字幕久久精品无码APP | 日本高清高色视频免费| 亚洲国产精品自在线一区二区| 亚洲综合色丁香婷婷六月图片 | 五月婷婷在线免费观看| 亚洲熟女精品中文字幕| 九九精品成人免费国产片| 国产成人无码a区在线观看视频免费| 亚洲成AV人片在WWW| 色噜噜AV亚洲色一区二区| 99re热精品视频国产免费| 一区二区亚洲精品精华液| 亚洲国产成人精品无码久久久久久综合| 亚洲熟妇无码久久精品| 全免费A级毛片免费看网站 | 蜜桃成人无码区免费视频网站| 亚洲一卡2卡3卡4卡国产网站 | 国产美女精品视频免费观看| 99免费精品视频| 亚洲综合激情五月丁香六月| 国产AV无码专区亚洲AV手机麻豆| h在线观看视频免费网站|