.NET Windows Service Runner
I've had a lot of people say that the Service Loader I created is great, but that they would like the ability to run the service without a debugger attached, like from the command line or similar method, but still not require the service be installed as a Windows Service.
I created a new application as an enhancement to the original Service Loader called the Service Runner. What is beautiful about this is that it requires no code changes whatsoever to the service to run it without installing it. Not even the one line code change described in the original Service Loader article is necessary. Here's how it works.
- When you first run the program, it will ask you to select an assembly to find services in:
- If the application cannot find an app.config file automatically (it looks for <AssemblyName>.config just like the CLR does by default), it will allow you to specify one. If you do not need a config file, just hit cancel:
- If everything checks out, you'll see the old familiar Service Loader interface with Start, Stop, Pause, Resume, etc:
That's it. Note again that this required no code changes to the service to work.
There is a small caveat to this, however. None of your Main() function code (if you have any you care about) will execute. It's not very common to have any setup code in your Main() function for a service, but I know someone will email me about this so I just wanted to mention it.
Design Considerations
I was not comfortable with using the original Service Loader to allow execution outside of Visual Studio because it was designed as a debugging aid only. I wanted there to be no way it would accidentally execute when deployed. Any technique I could come up with for doing this was too invasive, risky, or hard to use.
I decided to create a service runner application that would use the same techniques that the Service Loader did, but be outside of the application. Basically it loads the assembly you chose, finds all of the ServiceBase types and manually loads them into the Service Loader. Even if you select an executable, it doesn't actually execute it - it uses it just like a library.
Because it's more of an outside-looking-in solution, it has even less risk of affecting the application once it is deployed, but still gives you the flexibility of running the service without first installing it.
Download
I've updated the original Zip files to include the new source and executable. Just double-click ServiceRunner.exe and you should be able to run any .NET Windows Service.
Service Debugging Helper (Binary)
Service Debugging Helper (Binary + Source)
Bugs? Contact Me.
Trackbacks
No Trackbacks
Comments
Peter Müller
:
Stéphane
:
Simon
:
Pedro
:
marco
:
Andreas Saurwein
:
Andreas Saurwein
: