OT: Dynamically configure a Windows Service thru a monitoring app

OT: Dynamically configure a Windows Service thru a monitoring app

Old forum URL: forums.lhotka.net/forums/t/6459.aspx


SonOfPirate posted on Wednesday, February 18, 2009

I am developing a Windows Service application and would like to allow users to configure the behavior of the service during runtime.  My initial thoughts are to create an MMC snap-in that exposes the properties that may be changed but I'd prefer to create an ASP.NET web app to allow remote management.

It seems that the easiest approach would be to have the settings defined in the app.config for the service application.  I don't want to use a database for the settings, including SQL Server Express, because I don't want to add such a requirement for the solution.

My problems are based on creating two applications, the service and the monitor, that access the same configuration file.  How can I accomplish this.  Is there a better approach?

 

tmg4340 replied on Thursday, February 19, 2009

Well... you have a couple of issues to consider.  Configuration-file data is cached by the .NET runtime, and it does not watch for file changes and automatically refresh the data.  So if your ASP.NET app does modify the service's configuration file (which you can certainly do - it's nothing more than an XML file to the website), you'd have to coordinate something with the Windows service to let it know to refresh the configuration info the next time it needs it.  You could implement a file watcher relatively easily, but ultimately you may have some concurrency issues to deal with.  That's probably going to be a relatively small concern, though.

A second issue is rights.  Presumably, you're not going to house the Windows service from the same folder that your website resides in.  That means your website ID (or the ID of the users, if you use Windows authentication and impersonation) have to have rights to the service directory.  I'm assuming that this probably isn't a big issue for you (e.g. you've already figured this one out), but just in case...

If you're not keen on SQL Server Express, what about SQL Server CE?  You don't have the overhead of SSE, and your database is a self-contained file.  You don't have the caching issues of configuration files (but you still could have some concurrency questions.)  You still have a rights issue, but like I said, I am assuming you've already worked that out.

HTH

- Scott

SonOfPirate replied on Thursday, February 19, 2009

Truthfully, no, we hadn't worked out the rights issues and you bring up a good point.  We've been using IIS as a model for our design where they have the MMC snap-in, service application and metabase all in the same folder.  The ASP.NET idea was based on IIS 7.0 providing the same but we didn't think much about rights issues.

I'm not very familiar with SQL CE.  How is that different from SQL Express?

 

tmg4340 replied on Thursday, February 19, 2009

SQL CE was originally designed to support mobile devices.  It's now also utilized in Microsoft's occasionally-connected-client scenarios.  If you create a "local cache" in VS 2008, you're creating a SQL CE database.

It's a database that is completely self-contained within a file.  There's no "server install" - just a single .NET DLL that you add as a reference to your project, and then your database file.  It works pretty much like any other data provider, but it's very simplified - no stored procedures, no user views, just tables and indexes.  But for simple configuration information, it should work well.  Since it's just one file, you can pass it around however you need, and re-create it on the fly if you want to.

HTH

- Scott

Copyright (c) Marimer LLC