views:

192

answers:

3

i building a small windows service (not a web service) that periodically check for some data and based on that and call a class library to do some work

BTW: this is the first time i try to create a windows service

+4  A: 

There's some of stuff here, walk throughs architecture, etc. I guess the biggest mistake I see people making when they write a windows service is to try and somehow interact with the desktop or the user. Don't do that. :)

JP Alioto
+1  A: 

Check out this link.

hypoxide
+2  A: 

Windows services are by definition hard to test because you must always install them and uninstall them every time when you change something.

It is best to decouple BL that you writing for service and put it in a separate class. After that you can write simple win desktop application where you will use and test this BL class. After you finished testing it is easy to include same logic to a Windows Service project.

For debugging Windows Service you have to Attach to process and after that it is very easy to test code directly.

Hope that this will help...

zidane
really useful ty
Yassir
This is not the case. You can create a class that inherits from your service and exposes the service functionality for testing. That Class (I usually call it Host) can expose the protected OnStart, OnStop, etc. methods of your service as public methods (just create a public method that dispatches to the protected base class method). Then, you can create a form that drives your Host class to test your service. The only complexity is that your form's app.conig has to have the config settings that your service looks for.
JP Alioto
Decoupling was meant in a way that only BL is extracted in separate class. Debugging and testing just mechanics of the Windows Service itself was not my concern here.Another thing, logging into Event Log is also very useful technique for gathering data about Windows Service behavior.
zidane
Uninstall/re-install is not necessary.http://stackoverflow.com/questions/761120/windows-service-hard-to-debug-using-break-points/762146#762146
MattH