Wcf – How to read app.config from a custom location, i.e. from a database in .NET


I am trying to override the ApplyConfiguration method in my custom ServiceHost to read the configuration from a database instead of app.config. Ideally I would want to be able to do something like this:

Configuration config = GetConfigFromMyDatabase(…);

ServiceModelSectionGroup serviceModel = ServiceModelSectionGroup.GetSectionGroup(config);

Is there any way to do this without writing a temp app.config file?

Best Solution

What about using:

System.Configuration.ConfigurationManager.OpenExeConfiguration(string exePath)

That should let you open an arbitrary app.config file.