代码之家  ›  专栏  ›  技术社区  ›  sergiogx

在flex中停止Web服务?

  •  1
  • sergiogx  · 技术社区  · 16 年前

    是否可以停止执行Web服务?

    我有一个灵活的Web应用程序,它可以搜索同时具有全名和客户ID的客户机,当按名称搜索时,有时用户只需键入姓氏,这需要很长的时间。

    由于应用程序是在客户机排队等候时使用的,所以我希望能够停止搜索并使用他们的全名或ID,避免等待结果,然后必须在结果中手动搜索用户。

    谢谢

    编辑: 抱歉,我没有正确地解释自己,当我的意思是“Web服务”时,我实际上是指mx.rpc.soap.mxml.web service,我想阻止它等待结果事件和故障事件。谢谢。

    2 回复  |  直到 14 年前
        1
  •  1
  •   adamcodes    16 年前

    更新

    你可以使用 disconnect() 删除任何挂起的请求响应程序,但它也断开服务的连接。然后打电话 initialize() .

    更新

    无法停止Web服务的执行,因为这超出了flex应用程序的控制范围,但可以限制Web服务响应的处理。例如,在应用程序上,有一个按钮 Cancel Search 它设置了一个布尔值 bSearchCanceled 为真。
    Web服务调用检查的结果处理程序 搜索取消 ;如果为真,则返回。

        2
  •  2
  •   Curtis Rolando Quezada    14 年前

    实际上有一个 cancel(..) 方法显式地为此目的,虽然它有点埋葬。使用cancel方法将导致不调用结果和错误处理程序,还将删除繁忙的光标等。

    根据运行搜索的方式(如单独的工作进程等),还可以通过在 cancelSearch() Web服务方法来杀死这些工作进程并释放服务器资源等。

    private var _searchToken:AsyncToken;
    
            public function doSearch(query:String):void
            {
                _searchToken = this.searchService.doSearch(query);
            }
    
            protected function doSearch_resultHandler(event:ResultEvent):void
            {
                trace("doSearch result");
                trace("TODO: Do stuff with results");
                _searchToken = null;
            }
    
            protected function doSearch_faultHandler(event:FaultEvent):void
            {
                trace("doSearch fault: " + event.fault);
                _searchToken = null;
            }
    
            public function cancelSearch():void
            {
                var searchMessageId:String = _searchToken.message.messageId;
    
                // Cancels the last service invocation or an invokation with the
                // specified ID. Even though the network operation may still
                // continue, no result or fault event is dispatched.
                searchService.getOperation("doSearch").cancel(searchMessageId);
                _searchToken = null;
                trace("The search was cancelled, result/fault handlers not called");
    
                // TODO: If your web service search method is using worker processes
                // to do a search and is likely to continue processing for some time,
                // you may want to implement a 'cancel()' method on the web service
                // to stop any search threads that may be running.
            }
    
    推荐文章