views:

634

answers:

1

I Need add custom values to AppSettings in a webservice

i have this code, but nothing happens.

procedure TWebService1.AddStrConn(KeyConn, ValueConn: String);
var
config  : System.Configuration.Configuration;
begin
config:=ConfigurationManager.OpenExeConfiguration(System.Reflection.Assembly.GetExecutingAssembly().Location);
config.AppSettings.Settings.Add(KeyConn,ValueConn);
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection('appSettings');
end;

also try

procedure TWebService1.AddStrConn(KeyConn, ValueConn: String);
var
config  : System.Configuration.Configuration;
begin
config:=ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings.Add(KeyConn,ValueConn);
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection('appSettings');
end;
+2  A: 

You are using OpenExeConfiguration, which is intended for *.exe.config. To open web.config, try something like

Configuration cfg = WebConfigurationManager.OpenWebConfiguration("~");

It should allow you to save, provided your service has the privileges to do so.

Henk Holterman
thanks very much.
RRUZ