WCF Rest异步调用方法 [英] WCF Rest Asynchronous Calling Methods

查看:60
本文介绍了WCF Rest异步调用方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个开发的类库,该类库目前正在通过WCF REST服务调用,处理强度很高.

REST服务直接访问类库的DLL,而WCF rest服务或多或少是系统的接口.

假设定义了以下方法:

创建请求

启动一个耗时五分钟的线程,但是立即返回该进程生成的会话ID,该线程将在会话完成时向数据库报告该会话ID.

检查状态

接受会话ID并检查数据库以查看该过程是否已完成.

我不得不认为,有一种更好的管理"正在运行的线程的方法,但是,我的要求是,用户在发出请求后应立即收到REST服务的响应.

我正在使用WCF消息属性将XML返回到浏览器,并且由于可以从任何编程语言调用此应用程序,因此我不能使用经典的WCF和回调(我认为,如果我错了,请纠正我).

有时我会遇到一个问题,即发生错误,并且iscomplete事件从未写入数据库,因此检查状态"方法表示该问题永远存在.

在这种情况下,有人对正常做什么和可以做什么有任何想法吗?

谢谢!

Jeffrey Kevin Pry

解决方案

您的服务应返回缓存时间才开始循环.

如何处理服务器上的内容取决于您自己,而与REST无关.一方面,我会将所有作为后台线程执行的逻辑放在try/catch中,以便在发生错误时可以返回错误状态,并可以根据情况重试该操作.

I have a class library I developed that is rather processing intensive that I currently call through a WCF REST service.

The REST service directly accesses the DLLs for the class library and more or less the WCF rest service is an interface for the system.

Let's say the following methods are defined:

Create Request

Starts a thread that takes five minutes, but immediately returns a session ID that the process generates and the thread uses to report when it is completed to the database.

Check Status

Accepts a session id and checks the database to see if the process has completed.

I have to think that there is a better way to "manage" the threads running, however, my requirements state that the user should receive an immediate response from the REST service upon issuing a request.

I am using the WCF Message property to return XML to the browser and as this application can be called from any programming language I can't use classic WCF and callbacks (I think, correct me if I am wrong).

Sometimes I run into an issue where an error occurs and the iscomplete event never gets written to the database and therefore the "Check Status" method says it's processing forever.

Does anyone have any ideas about what is normally done and what can be done in this situation?

Thanks!

Jeffrey Kevin Pry

解决方案

Your service should return a 202 Accepted at the initial request with a way for the client to check the current status, either through the Location header or as part of the content.

As you indicate the client then polls the URL indicated to check the current status. I would also suggest adding a bit of cache time to this response in case a client just starts looping.

How you handle things on the server is up to you and in no way related to REST. For one thing I would put all logic that executes as the background thread in a try/catch to you can return an error status back if an error occurs and possibly retry the action depending on the circumstances.

这篇关于WCF Rest异步调用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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