I have created a webservice for my asp.net application. I published my Webservice in IIS also.I have used a timer inside webservice. But when the system get restarted the service get stopped or timer get stopped. How to start it automatically after the system get restarted?
Automatic WebService Start
Collapse
X
-
Hey shreears..... i think you're confused between windows services and web services....
It's Windows service that's gets started or stopped at system start.... and windows services are built for Desktop Applications... .
While Webservices are for the websites or webapplications hosted on the
web.... or in IIS for local use....
When you run your WebSite through IIS or Visual Studio .... you can call all of the methods of the Web service.... it doesn't needs to be started or stopped....
got it buddy !!!!! -
This is a very interesting problem.
I recommend that you create a Windows Service application that monitors when IIS is restarted....if it's restarted then it will have to send a request to your Web Service to "restart" it.
I have no idea how you would implement this Windows Service.
Alternatively you could re-design your Web Service in such a way that it doesn't require the timer control. Instead of having the timer control doing whatever, you could redesign your web service to do this process every connection....
If there are a lot of connections and this process uses a lot of resources, then have a static variable that contains a date/time of when the last "refresh" was....check that value first and only do the process when a connection is made if x amount of time has past since the last time the process was executed.
-FrinnyComment
-
Ok. Basically, what a web service is, is a web application with very specific input/output. Now, a web app doesn't run until it is called. So, your timer won't start until the application is started via a web request.
Therein lies the problem using timers in an ASP.NET web service. It's simply not the best idea.
If it is possible, I would create a Windows service that does all the work that needs the timer, and let the web service act solely as a communications layer.Comment
-
Hey.
Im no exactly a IIS/ASP.Net/Web-Service expert (I'm more into penguins :P), but this sounds to me like tho sort of thing the Task Scheduler (Cron, to me) was made for; executing things periodically on a timer.
Couldn't you just write a script - to either do whatever your web-service is doing on the timer, or to test whether IIS went down and restart the timer - and schedule it for periodic execution using the Task Scheduler?
Writing a windows service seems like overkill to me.
Not that I actually know how to do that. Could be easy, I suppose xDComment
-
The problem with the whole idea is that web services aren't really "services." They're basically web pages that expect a certain POSTed input, and return a response of specifically formatted XML.
Now, there is a component that runs in the background, but it's not something that you really "start." It's started when it's called via web request. So I guess you could just set up a script to do a web request, but it seems like the whole idea is faulty from the beginning.Comment
-
I would never refer to a Web Service as "basically a web page". I guess this is because I learned about Web Services in Java and have a clear understanding that they are not web pages...They are completely different animals. Microsoft has done a wonderful job of blurring the lines between web pages, web services, and even between client/server by adding in functionality to let you call web services client side using Ajax. Although this has made things easier for developers, it also adds confusion as to what each component is, how they work, where/how they are supposed to be used etc.
Aside from that, I completely agree with you iA.
The OP has has a design flaw in which they have confused a web service with a windows service. Web services wait for a request, process the request, and send a response. They aren't supposed to be sitting in the background doing something in between requests. That's not their intended usage.
But, if the user doesn't want to redesign their web service to work as web services are intended to work then they are going to have to either write a Web Service (which does run in the background on the Windows Web Server...waitin g for the IIS server to restart) or they are going to have to write a script as Atli has recommended. Either way I don't know how to do this and the question will have changed.
-FrinnyComment
Comment