Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / September 2007

Tip: Looking for answers? Try searching our database.

Configuration data for a Windows Service

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ttrudeau - 03 Sep 2007 18:20 GMT
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.)
sloan - 04 Sep 2007 01:09 GMT
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.

> I'm creating a Windows Service that will manage pluggable objects that
> perform certain work based on a set of interfaces.  The configuration data
[quoted text clipped - 17 lines]
> Documents and Settings; otherwise, I'd probably store at least the hosting
> object data as user settings in the application configuration file.)
ttrudeau - 04 Sep 2007 03:18 GMT
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?

> http://www.eggheadcafe.com/articles/20041204.asp
>
[quoted text clipped - 27 lines]
> > Documents and Settings; otherwise, I'd probably store at least the hosting
> > object data as user settings in the application configuration file.)
sloan - 04 Sep 2007 15:12 GMT
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/default.asp?url=/library/en-us/cpguide/html/cp
concreatingnewsectionhandlers.asp
)
 // also see http://support.microsoft.com/default.aspx?scid=kb;en-us;309045 
// Article ID : 309045

> That's a very nice solution that they put together.  The only problem is
> that
[quoted text clipped - 47 lines]
>> > hosting
>> > object data as user settings in the application configuration file.)
ttrudeau - 04 Sep 2007 22:26 GMT
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.)

> Then you'll have to add logic which says "here is where I'm going to get my
> config file".
[quoted text clipped - 88 lines]
> >> > hosting
> >> > object data as user settings in the application configuration file.)

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.