What is the difference between RemoteServiceServlet and RemoteService?

℡╲_俬逩灬. 提交于 2019-12-24 01:26:26

问题


I know that the first one is a class and the second is an interface but the point is, why should client Services extends the RemoteService and for the ServiceImpl class extends RemoteServiceServlet

So What is Actually behind the Scene ?!


回答1:


You're trying to compare apples and oranges. Please read docs and make any simple demo project to clearly understand these concepts.

RemoteService is the interface that RPC interfaces on client side should extend. And RemoteServiceServlet is the servlet base class for your RPC service implementations on the server. It deserializes requests from the client and serializes outgoing responses.

To use the RPC you need create and define in the client package own interface should extend the RemoteService interface and specifies methods the server should implement.

package com.yourproject.client;

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

public interface CustomInfoService extends RemoteService {
    Info getInfo(String infoId);
}

Then you need provide implementation of this interface by server side. This should be a servlet in server package which extends RemoteServiceServlet and implements the CustomInfoService.

package com.yourproject.server;

import com.yourproject.client.CustomInfoService;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

public class InfoServiceImpl extends RemoteServiceServlet implements CustomInfoService {
   public Info getInfo(String infoId) {
       //implementation (for example getting info from database)
   }
}

Sure to work properly you also need set the servlet mapping, create an asynchronous interface, make its call and process a result in a generated callback, implement the interface Serializable or IsSerializable for classes of instances which are pass over the RPC.




回答2:


RemoteService is a marker interface that allow GWT to find your RPC/RPCAsync interfaces (to validate them/do the link with your implementation).

RemoteServiceServlet is the servlet that receive the call from the client, deserialize the parameters, call your method, serialize what is returned by your method (exception or returned object), and send it to the client.



来源:https://stackoverflow.com/questions/13372633/what-is-the-difference-between-remoteserviceservlet-and-remoteservice

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!