I have a WCF Library and I’m trying to host it within a Windows Service.
When testing just the Library with WCF Test Client all is well. In my Library project I have an app.config with <connectionStrings> in the <configuration> element. I am specifying the location of a local database like so:
data source=C:\test\smMonitorLocalDB.sdf;
I have copied everything from the app.config in my Library project to the app.config in my Windows Service project EXCEPT the <connectionStrings> section. Because, if I add that <connectionStrings> section, my Windows Service won’t start.
If I leave out the <connectionStrings> section, my Windows Service starts just fine. It also works just fine ( except the parts of it that depend on the <connectionStrings> ).
So my question is: where should I be adding my <connectionStrings>? Or is there a better way for me to be going about this?
It turns out that the
app.configfile is only read when the Windows Service is INSTALLED. I had originally assumed that if the Windows Service was restarted that it would re-read theapp.config.If you are having difficulty trying to figure out why your Windows Service isn’t starting, check out the EventViewer, you may have some logs there.
It is very difficult to debug a Windows Service if it is not started, but it is possible. Check out this SO post if you’re having trouble.
Thanks to @J0HN for your help.