Automatic WebService Start

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shreears
    New Member
    • Nov 2009
    • 4

    Automatic WebService Start

    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?
  • ThatThatGuy
    Recognized Expert Contributor
    • Jul 2009
    • 453

    #2
    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 !!!!!

    Comment

    • shreears
      New Member
      • Nov 2009
      • 4

      #3
      Hi

      thk u for replying it

      Actually i am having a timercontrol inside my webservice.
      So when ever i restart the IIS that timer control get stopped.
      Hence i need to again startup that timer in webservice
      how to do it if the IIS get restarted...... .?

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

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

        -Frinny

        Comment

        • Curtis Rutland
          Recognized Expert Specialist
          • Apr 2008
          • 3264

          #5
          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

          • Atli
            Recognized Expert Expert
            • Nov 2006
            • 5062

            #6
            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 xD

            Comment

            • Curtis Rutland
              Recognized Expert Specialist
              • Apr 2008
              • 3264

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

              • Frinavale
                Recognized Expert Expert
                • Oct 2006
                • 9749

                #8
                Originally posted by insertAlias
                They're basically web pages that expect a certain POSTed input, and return a response of specifically formatted XML.
                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.

                -Frinny

                Comment

                • shreears
                  New Member
                  • Nov 2009
                  • 4

                  #9
                  Hi Friends


                  I know that some request has to be send to webservice for intialis it....

                  But i need to do it from windows or IIS Automatically.. ...
                  Kindly come up with solutions...

                  Comment

                  • Frinavale
                    Recognized Expert Expert
                    • Oct 2006
                    • 9749

                    #10
                    Did you read any of the posts in this thread?
                    We suggested quite a few possible solutions for you to consider.
                    What did you think of our suggestions?


                    -Frinny

                    Comment

                    • shreears
                      New Member
                      • Nov 2009
                      • 4

                      #11
                      Sorry i dont need of doing in Windows Service as suggested by above threads.
                      I need to do it in Web service itself. So i Searching For web Service itself..

                      Comment

                      • Frinavale
                        Recognized Expert Expert
                        • Oct 2006
                        • 9749

                        #12
                        What you want is not possible.
                        Web Services are started when a request is made to them. They do not and cannot start before a request is made to them.

                        That is why we suggested using a Windows Service.

                        Comment

                        Working...