I have a WCF server which has the following app.config file:
<?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>
At installation on a different machine, I want to make it to update automatically the address with the address of that machine. I have the string but I don't understand how to update the "address" item in the app.config file. I have the following code but this does not work:
var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings["address"].Value = "new_value";
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
I guess it is not working because I do not have the section named "appSettings", but how to access that "address" item ? I tried different solutions, but nothing works.
Thank you in advance.