簡體   English   中英

在Flex中停止Web服務?

[英]Stoping web service in flex?

是否可以停止執行Web服務?

我有一個Flex Web應用程序,該應用程序同時使用全名和客戶端ID來搜索客戶端,當按名稱搜索時,有時用戶會只鍵入姓氏,這會花費很長時間。

由於該應用程序是在客戶排隊等候時使用的,因此我希望能夠停止搜索並改用其全名或ID,避免等待結果,然后不得不在結果中手動搜索用戶。

謝謝

編輯:對不起,我沒有正確解釋自己,當我指的是“ Web服務”時,我實際上的意思是mx.rpc.soap.mxml.WebService,我想阻止它等待結果事件和故障事件。 謝謝。

實際上有一個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.
        }

更新

您可以使用disconnect()來刪除所有待處理的請求響應者,但是它也會斷開服務的連接。 然后調用initialize()

/更新

您無法停止執行Web服務,因為這超出了Flex應用程序的控制范圍,但是您可以限制Web服務響應的處理。 例如,在應用程序上,有一個諸如“ Cancel Search類的按鈕,該按鈕將boolean bSearchCanceled為true。
Web服務調用的結果處理程序檢查bSearchCanceled ; 如果為true,則返回。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM