开发者

Overriding App.Config settings

We have an app.config file that lists specific endpoint addresses and also some additional service settings. We would like to change these settings using an external config file set by the environment that it is placed in. What we would like it to do is dynamically read the external config file for that environment without hard开发者_如何学Python coding values.

I know there is a way to specify an external file in the section specific to that section. Is there a way to dynamically set this location?


I ended up just setting it to an external config file by modifying the setting with:

    System.Configuration.AppSettingsSection appsettings = config.AppSettings;
    appsettings.File = Environment.CurrentDirectory + "\\configs\\" + configFile;
    config.Save(ConfigurationSaveMode.Modified);
    ConfigurationManager.RefreshSection("appsettings");

That will allow you to dynamically set it to whatever config file you want it to be.


Your first question - yes, you can "override" any configuration section (such as <client>, <bindings> etc. not section group such as <system.serviceModel>) with an external file:

<client configSource="yourCustomClient.config" />

Visual Studio will highlight this with errors - but it works! - it's just a deficiency of Visual Studio's editor here.

Your second question: no, I don't believe there's any way to make this truly dynamic - the best I can think of is having some sort of an XML transformation of your config file at build and/or install time.


I do think this link will help you do dynamically load any App.Config file and use WCF services.

Yours, Alois Kraus


My recommendation is to do any wcf configuration within the xap and passing in the environment information as a parameter. All WCF configuration calls can be done through code without the use of the settings in the web.config

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜