简体   繁体   English

在Flex中停止Web服务?

[英]Stoping web service in flex?

is it possible to stop a web service from executing? 是否可以停止执行Web服务?

I have a flex web application that searches clients with both full name and client id, when searching by name sometimes the usuer just types the last name and it takes a long time. 我有一个Flex Web应用程序,该应用程序同时使用全名和客户端ID来搜索客户端,当按名称搜索时,有时用户会只键入姓氏,这会花费很长时间。

Since the app is used when clients are waiting in line, I would like to be able to stop the search and use their full name or id instead, and avoid waiting for the results and then having to search the user manually within the results. 由于该应用程序是在客户排队等候时使用的,因此我希望能够停止搜索并改用其全名或ID,避免等待结果,然后不得不在结果中手动搜索用户。

thanks 谢谢

edit: Sorry, I didn't explain myself correctly, when I meant "web service" I actually meant mx.rpc.soap.mxml.WebService, I want to stop it from waiting for the result event and the fault event. 编辑:对不起,我没有正确解释自己,当我指的是“ Web服务”时,我实际上的意思是mx.rpc.soap.mxml.WebService,我想阻止它等待结果事件和故障事件。 thanks. 谢谢。

There is actually a cancel(..) method explicitly for this purpose, though it is a little burried. 实际上有一个cancel(..)方法专门用于此目的,尽管它有些隐秘。 Using the cancel method will cause the result and fault handlers not to be called and will also remove the busy cursor etc. 使用cancel方法将导致不调用结果和错误处理程序,还将删除繁忙的光标等。

Depending on how you run your searches (ie. separate worker process etc), it is also possible to extend this by added in a cancelSearch() web service method to kill these worker processes and free up server resources etc. 根据您运行搜索的方式(例如,单独的工作进程等),还可以通过在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.
        }

Update 更新

You could use disconnect() to remove any pending request responders, but it also disconnects the service's connection. 您可以使用disconnect()来删除所有待处理的请求响应者,但是它也会断开服务的连接。 Then call initialize() . 然后调用initialize()

/Update /更新

You cannot stop the web service from executing, because that's beyond the Flex app's control, but you can limit the processing of the web service's response. 您无法停止执行Web服务,因为这超出了Flex应用程序的控制范围,但是您可以限制Web服务响应的处理。 For instance on the app, have a button like Cancel Search which sets a boolean bSearchCanceled to true. 例如,在应用程序上,有一个诸如“ Cancel Search类的按钮,该按钮将boolean bSearchCanceled为true。
The result handler for the web service call checks bSearchCanceled ; Web服务调用的结果处理程序检查bSearchCanceled ; if true just return. 如果为true,则返回。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM