views:

402

answers:

1
+2  Q: 

C# Request Queue

My Web Service uses another API to obtain data. I cache the data, clean it and return it do the user when they make a request. At the moment I am getting a lot of requests and because I can only access the data API 2 times per second, I am getting errors back which means some users don't get the data and other do.

What I want to do is add each request to a queue and process them 1 by one with a 0.4 second sleep between them. he queue would have to be running all the time to make sure that all request are processed.

How would I do this in ASP.NET 3.5?

+4  A: 

Briefly, I suggest you create a Windows Service to process an MSMQ queue. Your existing web service would put requests into that queue.

However, your service will need to become an asynchronous web service. This way, while "waiting" for a response, your service will not be blocking a request thread.

BTW, are you using ASMX web services or WCF services? This will determine how to make the service asynchronoous.

John Saunders
To be honest I am actually just using an MVC view page that returns JSON based on the details in the URL. The mvc controller gets the variables and sends a list of items to the viewpage for it to display. Is it really necessary to have a standalone Web Service to handle the requests? If so what type of service do you think would be best.
The_Lorax
Didn't you say you needed to queue the requests?
John Saunders
Yes, I need something to queue and handle them.
The_Lorax