Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在运行时WCF将端点信息写入app.config?_Wcf - Fatal编程技术网

如何在运行时WCF将端点信息写入app.config?

如何在运行时WCF将端点信息写入app.config?,wcf,Wcf,是否有办法在app.config文件中写入有关端点的信息? 实际上,我想从一个app.config文件中读取标记,然后将其写入另一个app.config文件的标记中 谁能告诉我怎么做 实际上,我有一个名为“WCFService.exe.config”的配置文件,我想在我的程序中读取它,所以我写的是: string path = Path.Combine(Application.StartupPath, "WCFService.exe.config"); Configuration config

是否有办法在app.config文件中写入有关端点的信息? 实际上,我想从一个app.config文件中读取
标记,然后将其写入另一个app.config文件的
标记中

谁能告诉我怎么做

实际上,我有一个名为“WCFService.exe.config”的配置文件,我想在我的程序中读取它,所以我写的是:

string path = Path.Combine(Application.StartupPath, "WCFService.exe.config");
Configuration config = ConfigurationManager.OpenExeConfiguration(path)  

ServicesSection serviceSection = ConfigurationManager.GetSection("system.serviceModel/services") as ServicesSection;

ServiceElementCollection sereleColl = serviceSection.Services;
但是我在sereleColl什么都没有。

看看

不过我不记得怎么做了

编辑:

要访问它,您必须添加对System.Configuration的引用

编辑2:

更改应用程序设置的方法如下:

Configuration config = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath);
AppSettingsSection appSettings = config.AppSettings;
KeyValueConfigurationElement setting = appSettings.Settings["MyAppSettingsKey"];
setting.Value = "newValue";
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
您可以通过键入以下内容访问WCF设置:

ConfigurationSectionGroup sct = config.SectionGroups["system.serviceModel"];
希望这有帮助

评论:

您的代码在这里运行良好。然而,我改变了

string path = Path.Combine(Application.StartupPath, "WCFService.exe.config");

这将使用当前运行的应用程序的配置文件。我不知道为什么你的路径不起作用。要么就是这样,要么配置文件中一定有错误?

请查看

不过我不记得怎么做了

编辑:

要访问它,您必须添加对System.Configuration的引用

编辑2:

更改应用程序设置的方法如下:

Configuration config = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath);
AppSettingsSection appSettings = config.AppSettings;
KeyValueConfigurationElement setting = appSettings.Settings["MyAppSettingsKey"];
setting.Value = "newValue";
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
您可以通过键入以下内容访问WCF设置:

ConfigurationSectionGroup sct = config.SectionGroups["system.serviceModel"];
希望这有帮助

评论:

您的代码在这里运行良好。然而,我改变了

string path = Path.Combine(Application.StartupPath, "WCFService.exe.config");

这将使用当前运行的应用程序的配置文件。我不知道为什么你的路径不起作用。要么就是这样,要么你的配置文件中一定有错误?

你调用“OpenExeConfiguration”-这将打开当前正在执行的应用程序的配置

您需要阅读.NET 2.0配置系统:CodeProject上的.NET配置系统有一个优秀的三部分系列:

有一系列非常好的文章介绍如何在CodeProject上揭开.NET 2.0配置系统的神秘面纱:

  • 强烈推荐!Jon Rista很好地解释了.NET 2.0中的配置系统。

    调用“OpenExeConfiguration”-这将打开当前正在执行的应用程序的配置

    您需要阅读.NET 2.0配置系统:CodeProject上的.NET配置系统有一个优秀的三部分系列:

    有一系列非常好的文章介绍如何在CodeProject上揭开.NET 2.0配置系统的神秘面纱:


  • 强烈推荐!Jon Rista很好地解释了.NET 2.0中的配置系统。

    实际上,我不想读取当前可执行文件的app.config,但我想读取另一个app.config文件“WCFService.exe.config”。我仍然可以使用您的方法加载其他配置。我唯一的想法是,您的配置文件中一定有错误,但我想您已经检查过了:-)marc_s是正确的,即使我们指定了路径,但加载的是可执行文件配置。您的意思是我可以读取任何配置文件,我只需要给出正确的路径。实际上我不想读取当前可执行文件的app.config,但我想读取另一个app.config文件,即“WCFService.exe.config”。我仍然可以使用您的方法加载其他配置。我唯一的想法是,您的配置文件中一定有错误,但是我想你已经看过了:-)marc_s是正确的,即使我们指定了一个路径,但加载的是可执行文件配置。你的意思是我可以读取任何配置文件,我只需要给出正确的路径。