I want to debug a service written in C# and the old fashioned way is just too long. I have to stop the service, start my application that uses the service in debug mode (Visual studio 2008), start the service, attach to the service process and then navigate in my Asp.Net application to trigger the service.
I basically have the service running in the background, waiting for a task. The web application will trigger a task to be picked up by the service.
What I would like to do is to have a console application that fires the service in an effort for me to debug. Is there any simple demo that anybody knows about?
I have used unit tests to debug difficult setups in the past, just write a unit test that calls whatever service method with whatever parameters and set debug breakpoints in the unit test.
Using testdriven.net or jetbrains testrunner makes it easier.
You might want to check out TopShelf as well in your adventures.
http://codebetter.com/blogs/dru.sellers/archive/2009/01/11/topshelf.aspx
http://code.google.com/p/topshelf/
TopShelf is another project that is perfect for this approach. It allows you to run a process as a service, or as a regular console application with minimal configuration.
I use this to check if my process is running as a service or not.
You can do something like this in the main entry point:
and in your OnStart Event handler:
You could call the service methods via reflection as seen below.
Using
Environment.UserInteractive
enables us to know if we are running as a console app or as a service.