您的位置:首页 > 其它

Making Remote Procedure Calls (GWT RPC) 学习笔记

2012-08-08 21:57 375 查看
1. Mechanism

Java components of the GWT RPC Mechanism

When setting up GWT RPC, you will focus on these three elements involved in calling procedures running on remote servers.

the service that runs on the server (the method you are calling)
the client code that invokes the service
the Java data objects that pass between the client and server

Both the server and the client have the ability to serialize and deserialize data so the data objects can be passed between them as ordinary text.



In order to define your RPC interface, you need to write three components:

Define an interface (StockPriceService) for your service that extends RemoteService and lists all your RPC methods.
Create a class (StockPriceServiceImpl) that extends RemoteServiceServlet and implements the interface you created above.
Define an asynchronous interface (StockPriceServiceAsync) to your service to be called from the client-side code.

A service implementation must extend RemoteServiceServlet and must implement the associated service interface.Notice that the service implementation does not implement the asynchronous version of the service interface.Every service implementation is ultimately
a servlet, but rather than extending HttpServlet, it extends RemoteServiceServlet instead.RemoteServiceServlet automatically handles serialization of the data being passed between the client and the server and invoking the intended method in your service implementation.

2. 我的解说

the service proxy class.,client和server通信的桥梁。有两组参数,一组是call server传的参数, 另一组是从sever端传回来的值。如:

import com.google.gwt.user.client.rpc.AsyncCallback;

public interface StockPriceServiceAsync {

void getPrices(String[] symbols, AsyncCallback<StockPrice[]> callback);

}

Create the service proxy class. create an instance of the service proxy class by calling GWT.create(Class).
private ArrayList<String> stocks = new ArrayList<String>();
private StockPriceServiceAsync stockPriceSvc = GWT.create(StockPriceService.class);
StockPriceService.class 是客服端的接口
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: