Web services 向webservice中的web.config添加值

Web services 向webservice中的web.config添加值,web-services,delphi,web-config,Web Services,Delphi,Web Config,我需要将自定义值添加到Web服务中的AppSettings 我有这个代码,但什么也没发生 procedure TWebService1.AddStrConn(KeyConn, ValueConn: String); var config : System.Configuration.Configuration; begin config:=ConfigurationManager.OpenExeConfiguration(System.Reflection.Assembly.GetExecut

我需要将自定义值添加到Web服务中的AppSettings

我有这个代码,但什么也没发生

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;
也尝试

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;

您正在使用OpenExeConfiguration,该配置用于*.exe.config。要打开web.config,请尝试以下操作

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

它应该允许您保存,前提是您的服务具有这样做的权限。

您使用的是OpenExeConfiguration,它用于*.exe.config。要打开web.config,请尝试以下操作

Configuration cfg = WebConfigurationManager.OpenWebConfiguration("~");
它应该允许您保存,前提是您的服务具有这样做的特权