Configuration data for a Windows Service

G

Guest

I'm creating a Windows Service that will manage pluggable objects that
perform certain work based on a set of interfaces. The configuration data
for the hosting object in the service contains the information to create the
individual pluggable objects (primarly type information -- what and where).
The configuration data for each pluggable object will contain data related to
what it does (i.e. more or less unique to the object). The service will run
under the NetworkService account. And there will be an MMC snap-in designed
to modify the configuration for the hosting and pluggable objects.

I'm pretty sure I want to store this information in XML configuration files
not the Registry or some database. Where would be the best place to store
them? (I assume the NetworkService account doesn't get a user folder under
Documents and Settings; otherwise, I'd probably store at least the hosting
object data as user settings in the application configuration file.)
 
S

sloan

http://www.eggheadcafe.com/articles/20041204.asp

Check out Peter's code for a windows service.

You're not as interested in.... the msmq or command pattern, but rather how
he deploys different dll's with their OWN config files.

I added some functionality to one of his libraries as well, you'll have to
search the forum for it.
 
G

Guest

That's a very nice solution that they put together. The only problem is that
it looks like it relies on the assembly being in a certain folder and
precludes it from being loaded in the GAC.

That restriction would certainly make things more clear-cut, but I'm not
sure if I want to add that restriction. Assuming, I cannot use application
configuration files for the pluggable services, what do you think would be a
good location?
 
S

sloan

Then you'll have to add logic which says "here is where I'm going to get my
config file".

One way would be to add a config section to the main app.config (of the
windows service) and then say:


<MyConfigFileLocations>
<file ForAssembly="mycompany.myapplication.dll"
Location="mycompany.myapplication.config" />

</MyConfigFileLocations>

Something like that.

You need ~~some~~ kind of rule that says where the config file is.

It can either be:
in the app.config of the hosting application
in the same directory as the hosting application
in the directory of where the .dll is ( the url I gave)
in a specific place, and you tell it where it is. (the solution above).


If you want GAC ability, but have multiple instantiations of it, then you'll
need to do something like I describe above.


If you need an example of how to create your own config section, then check
this:
http://sholliday.spaces.live.com/Blog/cns!A68482B9628A842A!138.entry

it has nothing to do with your problem, but shows how create objects from a
well defined (yours) xml schema, which resides in the app.config file.

You want to see how the EmailSmtpSettingsHandler creates a
SmtpServerSettings object.

Or look at:
// ( above exert from
http://msdn.microsoft.com/library/d...uide/html/cpconcreatingnewsectionhandlers.asp )
// also see http://support.microsoft.com/default.aspx?scid=kb;en-us;309045
// Article ID : 309045
 
G

Guest

More good information. Unfortunately, not an answer to my question. :)

The service will definitely use a configuration file for at least some of
its data. Whether or not that points to a separate configuration file that
stores the information for the pluggable objects or contains the details for
the pluggable objects itself is still on the table.

But, my question is really where should I put the auxillary files?
Obviously, the application's configuration file goes with the the PE. But,
the configuration files containing the additional details could go any number
of places. If my hosting application was a standard Windows Forms
application then it wouldn't be a problem. The user settings would get
stored on a per user basis. That doesn't really apply to a Windows Service
running as Network Service.

I hope this helps describe my question:

C:\Program Files\...\MyService.exe
C:\Program Files\...\MyService.exe.config

GAC\PluggableObjects1.dll
GAC\PluggableObjects2.dll

???\PluggableObjects1.xml
???\PluggableObjects2.xml

In this instance MyService.exe.config might contain entries like this:

<PluggableObject Id="1" AssemblyName="PluggableObjects1.dll ..."
ConfigFile="???\PluggableObjects1.xml" />
<PluggableObject Id="2" AssemblyName="PluggableObjects2.dll ..."
ConfigFile="???\PluggableObjects2.xml" />

So what it boils down to is the best folder to fill in for the "???" for
each pluggable object? Isolated storage wouldn't work, because the files
need to be accessible from a user context when being modfiied through an MMC
snap-in. Program Files is obviously not a good choice. I don't like the
idea of arbitrary folders off the root of the hard drive although I could be
convinced that's the best choice. (I'm also not suggesting that this be the
only option, but rather the default expected location.)
 

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