简体   繁体   English

Web服务器上的后台进程与ASMX Webservice

[英]Background process on webserver with an ASMX Webservice

I am facing an issue, i need to recieve user request through an asmx webservice and for each request i need to: 我正面临一个问题,我需要通过asmx webservice接收用户请求,并且我需要的每个请求:

1) Send back to the user an Id for his request. 1)向用户发回他的请求的Id。 Something like: "Your request has been received with id ####". 类似于:“您的请求已收到id ####”。 (The id is generated by the DB, an autoincrement column.) (id由DB生成,自动增量列。)

2) Start a background process without blocking the user for response, i mean the webservice sends back the Id and starts the process in background. 2)启动后台进程而不阻止用户进行响应,我的意思是webservice发回Id并在后台启动进程。

I understand that maybe i should use WCF but i think the server cant run it, but if you could talk me about the answer of this in both of them kind of services, much better. 我知道也许我应该使用WCF,但我认为服务器无法运行它,但如果你能在这两种服务中谈论我的答案,那就更好了。

I have no idea about doing this task. 我不知道做这个任务。 I will appreciate your help. 我将感谢你的帮助。

Usually I do this with the help of a scheduled task that starts a console application at regular intervals. 通常我会在定期启动控制台应用程序的计划任务的帮助下执行此操作。

The communication between the ASMX web service and the scheduled console application is done through the database where I fill a work item queue table. ASMX Web服务和计划的控制台应用程序之间的通信是通过我填充工作项队列表的数据库完成的。

With this (maybe not that elegant aproach) I get the following benefits: 有了这个(也许不是那么优雅的方法)我得到以下好处:

  • Bypass the background threading in ASP.NET altogether (which I honestly do not fully understand) 完全绕过ASP.NET中的后台线程(我真的不完全理解)
  • Make the background processing even work correctly if the ASP.NET application is being restarted. 如果重新启动ASP.NET应用程序,则后台处理甚至可以正常工作。

Depending on the requirements the scheduled task can run as often as needed, eg every 5 minutes or just once a day. 根据要求,计划任务可以根据需要经常运行,例如每5分钟或每天一次。

You could use MSMQ. 你可以使用MSMQ。 Create a queue to handle the incoming requests and a service to take tasks from the queue and process them. 创建一个队列来处理传入的请求和一个服务,以从队列中获取任务并处理它们。 It'a hard to suggest the 'right' solution without knowing more about your specifics. 如果不了解您的具体细节,很难建议“正确”的解决方案。

I would just run a background task (maybe in your global.asax) that works out of a queue of logged requests, picks them up and actually does them. 我只是运行一个后台任务(可能在你的global.asax中),它在一系列已记录的请求中运行,然后选择它们并实际执行它们。

Your .asmx method would then just be adding to this queue (including the ID), thus can immediately return to the user while the task is being processed in the background... 您的.asmx方法只会添加到此队列(包括ID),因此可以在后台处理任务时立即返回给用户...

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

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