Web Service as a background service

Discussion in 'ASP .Net Web Services' started by Jason Barnett, Oct 9, 2008.

  1. I'm trying to create a Web Service that acts like a Windows Service. It
    contains Start, Stop, and GetStatus methods. Invoking the Start method of
    the web service should kick off a timer and the Stop method stops the timer.
    I've been able to accomplish all by placing the timer in the Application
    object (to persist its state). However, the timer doesn't fire since the web
    method has finished executing (and the asmx file is unloaded?).

    I've tried creating a seperate thread in hopes that the worker thread would
    function after the web method finishes execution, but apparently that didn't
    work. I suspect I would need to create a seperate process that runs in the
    background, but I hope there's another way.

    Could someone give some direction on a quick and easy approach, if one exists?
     
    Jason Barnett, Oct 9, 2008
    #1
    1. Advertising

  2. Figured out a solution.

    In my web service codebehind file, I declare a static thread that points to
    a ParameterizedThreadStart delegate. The ParameterizedThreadStart delegate
    creates a System.Threading.Timer that does a callback to a static method
    responsible for performing the routine batch work. The codebehind file also
    includes Start, Stop, and GetStatus methods for managing the thread.


    "Jason Barnett" wrote:

    > I'm trying to create a Web Service that acts like a Windows Service. It
    > contains Start, Stop, and GetStatus methods. Invoking the Start method of
    > the web service should kick off a timer and the Stop method stops the timer.
    > I've been able to accomplish all by placing the timer in the Application
    > object (to persist its state). However, the timer doesn't fire since the web
    > method has finished executing (and the asmx file is unloaded?).
    >
    > I've tried creating a seperate thread in hopes that the worker thread would
    > function after the web method finishes execution, but apparently that didn't
    > work. I suspect I would need to create a seperate process that runs in the
    > background, but I hope there's another way.
    >
    > Could someone give some direction on a quick and easy approach, if one exists?
     
    Jason Barnett, Oct 9, 2008
    #2
    1. Advertising

  3. "Jason Barnett" <> wrote in message
    news:...
    > I'm trying to create a Web Service that acts like a Windows Service. It
    > contains Start, Stop, and GetStatus methods. Invoking the Start method of
    > the web service should kick off a timer and the Stop method stops the
    > timer.
    > I've been able to accomplish all by placing the timer in the Application
    > object (to persist its state). However, the timer doesn't fire since the
    > web
    > method has finished executing (and the asmx file is unloaded?).
    >
    > I've tried creating a seperate thread in hopes that the worker thread
    > would
    > function after the web method finishes execution, but apparently that
    > didn't
    > work. I suspect I would need to create a seperate process that runs in
    > the
    > background, but I hope there's another way.
    >
    > Could someone give some direction on a quick and easy approach, if one
    > exists?


    Yes. Use a Windows Service. Web Services aren't for this purpose, and it's
    not going to work.

    Windows Services are trivial to create. Why not use them, since that's what
    they're for. If you need the service to be triggered based on a client
    calling the web service, then have the web service send a message to the
    Windows Service.

    --
    John Saunders | MVP - Connected System Developer
     
    John Saunders, Oct 10, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mason66
    Replies:
    0
    Views:
    430
    mason66
    Jul 27, 2006
  2. JWL
    Replies:
    4
    Views:
    596
    Michael Winter
    Sep 26, 2006
  3. jc
    Replies:
    3
    Views:
    1,756
  4. jc
    Replies:
    1
    Views:
    1,384
    Neredbojias
    Mar 19, 2008
  5. Dj Frenzy
    Replies:
    3
    Views:
    325
    Robert
    Feb 10, 2004
Loading...

Share This Page