C# Getting a string from one config file to be used by multiple projects
In my project I have a Windows Service and a WCF Service doing some actions on the same folder on a computer. The location of that folder will be given by the user within an app.config file that is included in the Windows Service project.
Now, I want the WCF Service to know the location of that folder (the folder given by the user), without the user having to type it into the WCF Servi开发者_如何学Pythonce config file as well.
How would I go about doing that?
Thanks!
There are lots of possibilities here:
Add the path of the Windows Service's config file as a setting in the WCF service's config file, and use that path to read the file with an XML Reader.
Store the folder path in some centralized system, like a database or the registry, and have both services obtain the setting from that centralized placed.
Specify the path in each individual config file, but use a post build event to make sure they stay current. (For instance, maybe the post-build event retrieves the config setting from the DB and then writes it to the config file)
Have one service expose the configuration setting as a public service call. For instance, the WCF service could invoke a method on the Windows service to determine which path to process.
You can place it in the Machine.config, and both the WCF application and the Windows service can access it.
http://msdn.microsoft.com/en-us/library/ms229697(VS.71).aspx
精彩评论