我如何通过AsyncToken处理远程方法调用? [英] How do i handle Remote Method calls via AsyncToken?

查看:160
本文介绍了我如何通过AsyncToken处理远程方法调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 <?xml version =1.0encoding = UTF-8 >?; 
xmlns:s =library://ns.adobe.com/flex/spark
xmlns:mx =library://ns.adobe.com/flex/mxminWidth =955minHeight =600>

< fx:Script>
<![CDATA [
import argoseye.main.Golem;

导入mx.collections.ArrayCollection;
导入mx.rpc.AsyncResponder;
导入mx.rpc.AsyncToken;
导入mx.rpc.Responder;
导入mx.rpc.events.FaultEvent;
导入mx.rpc.events.InvokeEvent;
导入mx.rpc.events.ResultEvent;
导入mx.rpc.remoting.RemoteObject;
protected function button1_clickHandler(event:MouseEvent):void
{
var ro:RemoteObject = new RemoteObject(destination);
ro.endpoint =http://耶稣/ blazeds / messagebroker / amf;
ro.addEventListener(InvokeEvent.INVOKE,onInvoke);

var token:AsyncToken = new AsyncToken();
token.addResponder(新的AsyncResponder(onResult,onFault));

token = ro.getCells();
textfeld.text = textfeld.text +Clickhandler called .... \\\
;


$ b public function onResult(event:ResultEvent,token:Object):void {
textfeld.text = textfeld.text +Resulthandler called ... \\\
;
var cellList:ArrayCollection = event.result as ArrayCollection;


$ b public function onFault(event:FaultEvent,token:Object):void
{
textfeld.text = textfeld.text +Faulthandler叫...... \\\
;


public function onInvoke(event:InvokeEvent):void {
textfeld.text = textfeld.text +Invokehandler called .... \\\
;
}
]]>
< / fx:Script>

< fx:声明>
<! - 在这里放置非可视元素(例如服务,值对象) - >
< / fx:声明>
< / s:Application>

输出为

lockquote $ b $



Resulthandler不会被调用,所有BlazeDS控制台都会注册一个成功的Resultevent。我做错了什么?



编辑:我试着将程序导出到一个类,应该管理这些东西。

  package argoseye.main 

{
import flash.events.Event;

  import mx.collections.ArrayCollection; 
导入mx.messaging.ChannelSet;
导入mx.messaging.channels.AMFChannel;
导入mx.rpc.AsyncResponder;
导入mx.rpc.AsyncToken;
导入mx.rpc.events.FaultEvent;
导入mx.rpc.events.ResultEvent;
导入mx.rpc.remoting.RemoteObject;

public class Schem
{
public var info:String =;

$ b public function Schem()
{
}

public function loadCurrentSchem():void
{
var ro:RemoteObject = new RemoteObject(Hibernatetest);
ro.endpoint =http:// jesus / blazeds / messagebroker / amf;

var token:AsyncToken = ro.getCells();
token.addResponder(新的AsyncResponder(onResult,onFault));

info = info +Loader Called ...;



$ b public function onResult(event:ResultEvent,token:Object):void {
var cellList:ArrayCollection = event.result as ArrayCollection ;
info = info +Resulthandler Called;


$ b public function onFault(event:FaultEvent,token:Object):void
{

}
/ / Eventhandlers


// Getters,Setters


}

}



如果我打电话,它不会到达事件处理程序。我的错在哪里?

解决方案

你的错误在于这些行:

  var token:AsyncToken = new AsyncToken(); 
token.addResponder(新的AsyncResponder(onResult,onFault));
token = ro.getCells();

您正在第1行创建一个新的令牌。
您在线分配一个应答者2.
然后你重新分配第3行的标记。

你在第3行做的是有效地创建一个新的标记,因此它没有因为它是一个新的实例。

所以应该是:

  var token:AsyncToken = ro.getCells(); 
//root.getCells()将返回一个AsyncToken的新实例
token.addResponder(新的AsyncResponder(onResult,onFault));


So here is the mxml i would like to get working:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">

    <fx:Script>
        <![CDATA[
            import argoseye.main.Golem;

            import mx.collections.ArrayCollection;
            import mx.rpc.AsyncResponder;
            import mx.rpc.AsyncToken;
            import mx.rpc.Responder;
            import mx.rpc.events.FaultEvent;
            import mx.rpc.events.InvokeEvent;
            import mx.rpc.events.ResultEvent;
            import mx.rpc.remoting.RemoteObject;
            protected function button1_clickHandler(event:MouseEvent):void
            {
                var ro:RemoteObject = new RemoteObject("destination");
                ro.endpoint = "http://Jesus/blazeds/messagebroker/amf";
                ro.addEventListener(InvokeEvent.INVOKE,onInvoke);

                var token:AsyncToken = new AsyncToken();
                token.addResponder(new AsyncResponder(onResult,onFault));

                token = ro.getCells();
                textfeld.text = textfeld.text + "Clickhandler called .... \n";

            }

            public function onResult(event:ResultEvent,token:Object):void {
                textfeld.text = textfeld.text + "Resulthandler called .... \n";
                var cellList:ArrayCollection = event.result as ArrayCollection;

            }

            public function onFault(event:FaultEvent,token:Object):void
            {
                textfeld.text = textfeld.text + "Faulthandler called .... \n";
            }

            public function onInvoke(event:InvokeEvent):void {
                textfeld.text = textfeld.text + "Invokehandler called .... \n";
            }
        ]]>
    </fx:Script>

    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <s:Button x="1093" y="575" label="Button" click="button1_clickHandler(event)"/>
    <s:TextArea x="1022" y="183" id="textfeld"/>
</s:Application>

The output is

Invokehandler called ....

Clickhandler called ....

The Resulthandler doesnt get called, allthough the BlazeDS Console registers an successfull Resultevent. What do I do wrong?

Edit: I tried exporting the procedure into a class, which is supposed to manage these things.

package argoseye.main

{ import flash.events.Event;

import mx.collections.ArrayCollection;
import mx.messaging.ChannelSet;
import mx.messaging.channels.AMFChannel;
import mx.rpc.AsyncResponder;
import mx.rpc.AsyncToken;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.remoting.RemoteObject;

public class Schem
{
    public var info:String="";


    public function Schem()
    {       
    }

    public function loadCurrentSchem():void
    {
        var ro:RemoteObject = new RemoteObject("Hibernatetest");
        ro.endpoint = "http://jesus/blazeds/messagebroker/amf";

        var token:AsyncToken = ro.getCells();
        token.addResponder(new AsyncResponder(onResult,onFault));

        info = info + "Loader Called ...";


    }

    public function onResult(event:ResultEvent,token:Object):void {
        var cellList:ArrayCollection = event.result as ArrayCollection;
        info = info + "Resulthandler Called";

    }

    public function onFault(event:FaultEvent,token:Object):void
    {

    }
    //Eventhandlers


    //Getters, Setters


}

}

If i call it, it doesnt reach the eventhandler. Where is my mistake?

解决方案

Your error lies in these lines:

var token:AsyncToken = new AsyncToken();
token.addResponder(new AsyncResponder(onResult,onFault));
token = ro.getCells();

You're creating a new token on line 1. You assign a responder on line 2. And then you reassign the token on line 3.

What you do on line 3 is effectively creating a new token, thus it doesn't have the responder attached to it, because it's a new instance.

So it should be:

var token:AsyncToken = ro.getCells(); 
//ro.getCells() will return a new instance of AsyncToken
token.addResponder(new AsyncResponder(onResult,onFault));

这篇关于我如何通过AsyncToken处理远程方法调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆