xmlRpc应用

图片内容转自: http://ws.apache.org/xmlrpc/server.html


个人补充:
主要过程看上面图片或者链接地址。
Server端:重要的是要写个XmlRpcServlet.properties文件来存放 Handler的指定,得把这个文件放到jar包里面才行。目录也得是指定的那个。
Client端:
import java.net.URL;
import java.util.Vector;

import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
import org.apache.xmlrpc.client.XmlRpcCommonsTransportFactory;

public class Client {
    public static void main(String[] args) throws Exception {
        // create configuration
        XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
        config.setServerURL(new URL("http://127.0.0.1:8080/xmlrpc/"));
        //这里这个地址是根据web.xml中配置的servlet来的
        config.setEnabledForExtensions(true);  
        config.setConnectionTimeout(60 * 1000);
        config.setReplyTimeout(60 * 1000);

        XmlRpcClient client = new XmlRpcClient();
      
        // use Commons HttpClient as transport
        client.setTransportFactory(
            new XmlRpcCommonsTransportFactory(client));
        // set configuration
        client.setConfig(config);

        // make the a regular call
        Object[] params = new Object[]
              { new Integer(2), new Integer(3) };
     //Calculator.add, Calculator 是在XmlRpcServlet.properties中配置的, add 是Handle中的方法
          Integer result = (Integer) client.execute("Calculator.add", params);
          System.out.println("2 + 3 = " + result);
    }
}


运行Server,执行Client,便可出执行的结果。
再来个类似的小例子。

你可能感兴趣的:(apache,xml,.net,Web,servlet)