简体   繁体   中英

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:

1) Send back to the user an Id for his request. Something like: "Your request has been received with id ####". (The id is generated by the DB, an autoincrement column.)

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.

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.

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.

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)
  • Make the background processing even work correctly if the ASP.NET application is being restarted.

Depending on the requirements the scheduled task can run as often as needed, eg every 5 minutes or just once a day.

You could use 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.

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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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