【问题标题】:QooxDoo FrontEnd + Python BackEnd ( SimpleXMLRPCServer) problemsQooxDoo FrontEnd + Python BackEnd (SimpleXMLRPCServer) 问题
【发布时间】:2013-04-23 15:36:31
【问题描述】:

我尝试过 Qooxdoo 并使用 SimpleXMLRPCServer 制作了一个简单的 Python 服务器,通过 Python 测试我可以毫无问题地获取数据,但是我可以从 Qooxdoo 获取这些数据吗?我迷路了,我已经搜索了 3 天,但没有找到解决方案。

我试试这个:

var JSON_lista_empresas = 1000
button1.addListener("execute", function(e) 
{
    var rpc = new qx.io.remote.Rpc();
    rpc.setServiceName("get_data");
    //rpc.setCrossDomain(true);
    rpc.setUrl("http://192.168.1.54:46000");
    rpc.addListener("completed", function(event)
    {
        console.log(event.getData());
    });
    rpc.callAsync( JSON_lista_empresas, '');
});

我尝试了其他选项但一无所获:(

文件链接:

http://mieresdelcamin.es/owncloud/public.php?service=files&dir=%2Fjesus%2Ffiles%2FQooxdoo

我尝试并阅读了所有 qooxdoo-contrib。


嗯,

RpcPython --> 好的

在 class/qooxdoo -> test.py

运行服务器 [start-server.py] 并从 webroser 查询:

http://127.0.0.1:8000//?_ScriptTransport_id=1&nocache=1366909868006&_ScriptTransport_data={%22service%22%3A%22qooxdoo.test%22%2C%22method%22%3A%22echo%22%2C%22id%22%3A1%2C%22params%22%3A[%22Por%20fin%22]}

webroser 中的回复是:

qx.io.remote.ScriptTransport._requestFinished(1,{"error": null, "id": 1, "result": "客户说:[Por fin]"});

但如果我从 qooxdoo 查询,例如回复是 [error.png]

qooxdoo 的代码:

var rpc = new qx.io.remote.Rpc( "http://127.0.0.1:8000/");
    rpc.setCrossDomain( true);
    rpc.setServiceName( 'qooxdoo.test');
// asynchronous call
    var handler = function(result, exc) {
        if (exc == null) {
            alert("Result of async call: " + result);
        } else {
            alert("Exception during async call: " + exc+ result);
        }
    };
rpc.callAsync(handler, "echo", "Por fin");

我输了:((

文件在:

http://mieresdelcamin.es/owncloud/public.php?service=files&dir=%2Fjesus%2Ffiles%2FQooxdoo

好吧,使用 Firebug,owncloud qx.io.remote.ScriptTransport 中的这个错误......被检测到

¿?.............

最好的问候。

【问题讨论】:

    标签: python rpc qooxdoo simplexmlrpcserver


    【解决方案1】:

    我猜您将 XML-RPC 与 JSON-RPC 混淆了,而 qooxdoo 仅支持后者。这些协议相似,但数据交换格式不同(XML 或 JSON)。除了SimpleXMLRPCServer,您可以在服务器端使用“RpcPython”,这是一个 qooxdoo contrib 项目。

    见:

    一旦您启动并运行此服务器,您应该能够对其进行测试:

    之后,您的 qooxdoo(客户端)代码也有望正常工作。 :)

    【讨论】:

      【解决方案2】:

      好的,

      在qxjsonrc模块的http.py文件中第66行更改

      response='qx.io.remote.ScriptTransport._requestFinished(%s,%s);'%(scriptTransportID,response)
      

      response='qx.io.remote.transport.Script._requestFinished(%s,%s);'%(scriptTransportID,response)
      

      并且运行良好:))

      此包修改链接:

      http://mieresdelcamin.es/owncloud/public.php?service=files&dir=%2Fjesus%2Ffiles%2FQooxdoo

      最好的问候和感谢!!!

      【讨论】:

        【解决方案3】:

        正如 Richard 已经指出的那样,Qooxdoo 仅支持其 JSON-RPC 风格。

        我维护了一个名为 QooxdooCherrypyJsonRpc 的原始 rpcpython 的分支。主要目标是将传输协议交给一些健壮的框架,只留下 JSON RPC 的东西。 CherryPy 显然是一个健壮的框架,允许 HTTP、WSGI 和 FastCGI 部署。代码被重构并被测试覆盖。后来我添加了上传/下载支持和一致的时区日期时间交换。

        至少您的 Python 后端可能看起来像(称为 test.py):

        import cherrypy
        import qxcpjsonrpc as rpc
        
        class Test(rpc.Service):
        
          @rpc.public
          def add(self, x, y):
            return x + y
        
        config = {
          '/service' : {
            'tools.jsonrpc.on' : True
          },
          '/resource' : {
            'tools.staticdir.on'  : True,
            'tools.staticdir.dir' : '/path/to/your/built/qooxdoo/app'
          }
        }
        cherrypy.tools.jsonrpc = rpc.ServerTool()
        
        if __name__ == '__main__':
          cherrypy.quickstart(config = config)
        

        然后你可以在你的qooxdoo代码中做如下:

        var rpc = new qx.io.remote.Rpc();
        rpc.setServiceName('test.Test');
        rpc.setUrl('http://127.0.0.1:8080/service');
        rpc.setCrossDomain(true); // you need this for opening app from file://
        rpc.addListener("completed", function(event)
        {
          console.log(event.getData());
        });
        rpc.callAsyncListeners(this, 'add', 5, 7);
        

        或者直接打开链接:

        http://127.0.0.1:8080/service?_ScriptTransport_id=1&_ScriptTransport_data=%7B%22params%22%3A+%5B12%2C+13%5D%2C+%22id%22%3A+1%2C+%22service%22%3A+%22test.Test%22%2C+%22method%22%3A+%22add%22%7D
        

        有关更多信息,请查看我在上面发布的包页面。

        【讨论】:

          【解决方案4】:

          Richard Sternagel 写了关于 rpcpython 的文章。此版本的 rpcpython 不适用于当前版本的 simplejson。因为 json.py 中的导入不正确:

              from simplejson.decoder import ANYTHING
              from simplejson.scanner import Scanner, pattern
          

          改进 rpcpython 或使用其他服务器,例如 CherryPy。

          【讨论】:

            猜你喜欢
            • 2020-10-07
            • 2020-10-11
            • 2019-03-28
            • 2022-12-19
            • 2011-09-24
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多