【发布时间】:2011-11-15 07:39:34
【问题描述】:
我正在尝试创建一个工具来以编程方式修改我的服务的 app.config 文件。代码是这样的,
string _configurationPath = @"D:\MyService.exe.config";
ExeConfigurationFileMap executionFileMap = new ExeConfigurationFileMap();
executionFileMap.ExeConfigFilename = _configurationPath;
System.Configuration.Configuration config = ConfigurationManager.OpenMappedExeConfiguration(executionFileMap, ConfigurationUserLevel.None);
ServiceModelSectionGroup serviceModeGroup = ServiceModelSectionGroup.GetSectionGroup(config);
foreach (ChannelEndpointElement endpoint in serviceModeGroup.Client.Endpoints)
{
if (endpoint.Name == "WSHttpBinding_IMyService")
{
endpoint.Address = new Uri("http://localhost:8080/");
}
}
config.SaveAs(@"D:\MyService.exe.config");
但是我在更改端点的身份时遇到了问题。
我想要类似的东西:
<identity>
<userPrincipalName value="user@domain.com" />
</identity>
对于我的端点配置,但是当我尝试时:
endpoint.Identity = new IdentityElement(){
UserPrincipalName = UserPrincipalNameElement() { Value = "user@domain.com" }
}
它失败是因为属性endpoint.Identity 和identityElement.UserPrincipalName 是只读的(我不知道为什么,因为 entity.Address 不是只读的)
有没有办法绕过这个限制并设置身份配置?
【问题讨论】:
标签: .net wcf configuration app-config