Web Service as a background service


J

Jason Barnett

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?
 
Ad

Advertisements

J

Jason Barnett

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.
 
Ad

Advertisements

J

John Saunders

Jason Barnett said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top