【问题标题】:Why do you need synchronous interface for GWT RPC?为什么 GWT RPC 需要同步接口?
【发布时间】:2014-11-19 11:22:26
【问题描述】:

我想知道为什么在使用 GWT RPC 时还需要定义一个同步接口,因为所有调用都是异步的 (http://www.gwtproject.org/doc/latest/DevGuideServerCommunication.html)?

我没有看到同步接口在哪里使用!

即为什么我们不能在我们的服务实现类中实现同步接口?

【问题讨论】:

    标签: java ajax gwt rpc


    【解决方案1】:

    来自文档:

    http://www.gwtproject.org/doc/latest/DevGuideServerCommunication.html#DevGuideCreatingServices

    此同步接口是您的服务规范的最终版本。此服务在服务器端的任何实现都必须扩展 RemoteServiceServlet 并实现此服务接口。

    package com.example.foo.server;
    
    import com.google.gwt.user.server.rpc.RemoteServiceServlet;
    import com.example.client.MyService;
    
    
    public class MyServiceImpl extends RemoteServiceServlet implements
        MyService {
    
      public String myMethod(String s) {
        // Do something interesting with 's' here on the server.
        return s;
      }
    }
    

    提示:无法直接从客户端调用此版本的 RPC。你必须创建一个异步的

    【讨论】:

    • 这是否意味着我的服务实现正在与同步接口而不是异步交互?但调用是异步的?通过阅读 gwt 项目主页上的文档,我无法完全理解它。
    • 我找到了这篇关于 RemoteService 是什么的 MarkerInterface 的文章,但它没有说明 RemoteService 的使用方式和用途以及与 GWT 的连接:javarevisited.blogspot.dk/2012/01/…
    • 同步接口做了两件事:一是在服务器端使用,二是触发生成rpc代理。
    • 同步类和异步类的联系在哪里?
    • 客户端使用异步接口,服务端使用同步接口,GWT用来识别代码生成器。同步总是扩展 RemoteService,它会告诉 GWT 使用 RpcServiceGenerator。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-11
    • 2013-05-07
    • 2011-10-01
    • 2016-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多