我有一个 WCF 服务器,它具有以下 app.config 文件:
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<services>
<service name="MyService" behaviorConfiguration="DiscoveryBehavior">
<endpoint address="net.tcp://192.168.150.130:44424/ServerService/"/>
<endpoint name="udpDiscovery" kind="udpDiscoveryEndpoint"/>
</service>
</services>
</system.serviceModel>
</configuration>
在另一台机器上安装时,我想让它使用该机器的地址自动更新地址。我有字符串,但我不明白如何更新 app.config 文件中的“地址”项。我有以下代码,但这不起作用:
var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings["address"].Value = "new_value";
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
我想它不起作用,因为我没有名为“appSettings”的部分,但是如何访问该“地址”项?我尝试了不同的解决方案,但没有任何效果。
先感谢您。