Programming synchronous web service calls in flex

蓝咒 提交于 2019-12-25 03:34:10

问题


Web service calls are asynchronous in flex, but I wanted to wrap a web service call in a class to provide synchronous encapsulation. Something like the below - the user could call getMyMethodResult and get the result returned by the web service. I expected the thread that recieved the soap response would populate the variable _result and mean that getMyMethod would, after a time, find _result is not longer null. But it doesn't! Can anyone explain why this does not work?

public class myClass
{   
    private var _result:Object;
    public function myClass()
    {
        //create a web service object
        ...

        // Add listener
        _service.addMyMethodListener(myMethodListener);
    }

    public function getMyMethodResult()
    {
        _service.myMethod();

        while (_result == null)
        {
        // count a variable or something (unimportant)
        }

        return _result;
    }

    private function myMethodListener(event:Event):void
    {
        _result = event.result;
    }
}

回答1:


There's is absolutely no support for that. The event loop runs between frames and as long as you block the execution with your (infinite) loop, your myMethodListener function will not be called. Anyway, this would be a terrible idea since the absence of threading in the Flash Player will cause your UI to freeze while you wait for your service to return. You should just drop that idea.



来源:https://stackoverflow.com/questions/1300372/programming-synchronous-web-service-calls-in-flex

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