【问题标题】:Using mx:RemoteObject with web2py's @service.amfrpc decorator将 mx:RemoteObject 与 web2py 的 @service.amfrpc 装饰器一起使用
【发布时间】:2009-05-29 16:52:51
【问题描述】:

我正在使用 web2py (v1.63) 和 Flex 3。web2py v1.61 引入了 @service 装饰器,它允许您使用 @service.amfrpc 标记控制器功能。然后,您可以使用http://..../app/default/call/amfrpc/[function] 远程调用该函数。见http://www.web2py.com/examples/default/tools#services。有没有人举例说明如何设置 Flex 3 来调用这样的函数?到目前为止,这是我尝试过的:

<mx:RemoteObject id="myRemote" destination="amfrpc" source="amfrpc"
    endpoint="http://{mysite}/{myapp}/default/call/amfrpc/">
    <mx:method name="getContacts"
        result="show_results(event)"
        fault="on_fault(event)" />
</mx:RemoteObject>

在我的场景中,destination 和 source 属性的值应该是多少?我已经阅读了几篇关于非 web2py 实现的文章,例如 http://corlan.org/2008/10/10/flex-and-php-remoting-with-amfphp/,但它们使用 .../gateway.php 文件而不是直接映射到函数的 URI。

另外,我已经能够使用 flash.net.NetConnection 成功调用我的远程函数,但我发现的大多数文档都认为这是旧的、Flex 3 之前的 AMF 方式。见http://pyamf.org/wiki/HelloWorld/Flex。这是 NetConnection 代码:

gateway = new NetConnection();
gateway.connect("http://{mysite}/{myapp}/default/call/amfrpc/");
resp = new Responder(show_results, on_fault);
gateway.call("getContacts", resp);

-罗伯

【问题讨论】:

    标签: python apache-flex flex3 web2py pyamf


    【解决方案1】:

    我还没有找到将 RemoteObject 与 @service.amfrpc 装饰器一起使用的方法。但是,我可以使用 NetConnection(类似于我最初发布的内容)使用较旧的 ActionScript 代码,并将其与 web2py 端的 @service.amfrpc 函数配对。这似乎工作正常。您想在我最初共享的 NetConnection 代码中更改的一件事是为连接状态添加一个事件侦听器。如果您觉得需要,您可以添加更多侦听器,但我发现 NetStatusEvent 是必须的。如果服务器没有响应,将触发此状态。您的连接设置如下所示:

    gateway = new NetConnection();
    gateway.addEventListener(NetStatusEvent.NET_STATUS, gateway_status);
    gateway.connect("http://127.0.0.1:8000/robs_amf/default/call/amfrpc/");
    resp = new Responder(show_results, on_fault);
    gateway.call("getContacts", resp);
    

    -罗伯

    【讨论】:

      猜你喜欢
      • 2020-02-25
      • 2012-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-19
      • 2016-09-12
      • 1970-01-01
      相关资源
      最近更新 更多