Multithreaded Web Service? Need some ideas.

secvb
01-08-2004, 07:49 AM
I'm writing a web app that keeps track of the health of some backend servers. However, I don't want the IIS machine to have to create traffic to the backend every time a user views the web page. For this I wanted to use a web service that would query the backend every 2 minutes and keep the data cached, then serve it out to IIS whenever it got a request. At the moment, however, each time IIS queries the web service the web service ends up querying the backend. I was under the impression that a web service was more like a daemon, where you could have two threads, one for answering requests and one for caching data. Is there a way to do this with a web service or is there a better alternative? Thanks!

secvb
01-08-2004, 09:02 AM
I did some searching and it turns out it isn't even necessary to have two threads to achieve the kind of caching i'm looking for. In case it comes up again, simply use CacheDuration in your WebMethod declaration:

'set number of seconds to cache
'GetTime1 Web Service
<WebMethod(CacheDuration:=120)> _
Public Function GetTime1() _
As DateTime
Return DateTime.Now
End Function

It'll return the current time the first time, and that same time every time for the next 120 seconds. The next call after this 120 will cause the function to execute the rest of the procedure and return the current time. From the article:

http://www.fawcette.com/vsm/2002_09_14th/magazine/columns/qa/default_pf.aspx

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum