<!--[if !supportLists]--> i. <!--[endif]-->說明:使用XmlRpcClient可以發送請求,在請求當中我們需要提供所需要調用的方法名,以及方法參數,且參數需包裝到一個集合當中。
<!--[if !supportLists]--> ii. <!--[endif]-->代碼:
XmlRpcClient client = new XmlRpcClient("http://127.0.0.1:6666");
Vector<String> pars = new Vector<String>();
pars.addElement("nick");
Object result = client.execute("service.hello", pars);
System.out.println("The Result is : " + result);
<!--[if !supportLists]-->b) <!--[endif]-->發布服務:
<!--[if !supportLists]--> i. <!--[endif]-->說明:通過WebServer我們可以很方便的發布服務。其中添加到addHandler()當中的實例就是服務體,而“service”就表示服務名稱。當請求到達時,他會根據請求的名稱與查找服務體,然后在返回的實例上調用execute()方法。
<!--[if !supportLists]--> ii. <!--[endif]-->代碼:
WebServer server = new WebServer(6666);
server.addHandler("service", new Service());
server.start();
public class Service implements XmlRpcHandler {
public Object execute(String methodName, Vector args) throws Exception {