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

本文详细解释了在设置GWTRPC时,涉及的三个关键元素:服务器上的服务(调用的方法)、客户端调用服务的代码以及在客户端和服务器之间传递的Java数据对象。并介绍了如何定义RPC接口所需的三个组件:服务接口、服务实现类和异步服务接口。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.
GWT RPC Plumbing

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

  1. Define an interface (StockPriceService) for your service that extends RemoteService and lists all your RPC methods.
  2. Create a class (StockPriceServiceImpl) that extends RemoteServiceServlet and implements the interface you created above.
  3. 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 是客服端的接口




评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值