【发布时间】:2014-08-10 17:48:55
【问题描述】:
我尝试动态更改 app.config 文件的终点地址。在我打印地址时更改后,我得到更改后的地址。但是该服务似乎没有使用该地址。即使我输入了错误的地址,它似乎也可以工作。似乎它正在使用默认地址。请帮忙。我的代码如下:
static void UpdateAppConfig(String Name)
{
var doc = new XmlDocument();
doc.Load(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
XmlNodeList endpoints = doc.GetElementsByTagName("endpoint");
foreach (XmlNode item in endpoints)
{
var addressAttribute = item.Attributes["address"];
if (!ReferenceEquals(null, addressAttribute))
{
addressAttribute.Value = "http://" + Name + "/test1/test2.svc";
}
}
doc.Save(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
}
【问题讨论】:
标签: c# xml wcf app-config service-reference