[英]Modify web.config system.ServiceModel/client/endpoint with Microsoft.Web.Administration.ServerManager
I'm having a bit of grief trying to modify my web applications web.config file using the Microsoft.Web.Administration.ServerManager
library. 尝试使用
Microsoft.Web.Administration.ServerManager
库修改Web应用程序web.config文件时,我感到有些悲伤。
What I am trying to do is modify the client
section located in System.ServiceModel
. 我想做的是修改
System.ServiceModel
的client
部分。
Basically I would like to take an entry like this 基本上我想输入这样的内容
<system.serviceModel>
<client>
<endpoint address="net.tcp://localhost:123/MyService.svc"
behaviorConfiguration="DefaultBehaviour" binding="netTcpBinding"
bindingConfiguration="TCPBinding" contract="MyService.IMyService"
name="MyService" />
</client>
</system.serviceModel>
and change it to this 并将其更改为此
<system.serviceModel>
<client>
<endpoint address="net.tcp://192.168.0.1:123/MyService.svc"
behaviorConfiguration="DefaultBehaviour" binding="netTcpBinding"
bindingConfiguration="TCPBinding" contract="MyService.IMyService"
name="MyService" />
</client>
</system.serviceModel>
I've been able to get as far as retrieving the SectionGroup as such 我已经能够尽可能地检索SectionGroup
using (ServerManager server = new ServerManager())
{
var siteConfig = server.Sites.First().GetWebConfiguration();
var clientSection = siteConfig.GetEffectiveSectionGroup().SectionGroups["system.ServiceModel"].Sections["client"];
}
but I am completely stuck as to how I can modify the actual entry. 但是我完全无法修改实际的条目。
Any guidance would be sincerely appreciated. 任何指导将不胜感激。
You can modify the attribute like this: 您可以像这样修改属性:
using (ServerManager server = new ServerManager())
{
var siteConfig = server.Sites.First().GetWebConfiguration();
var section = siteConfig.GetSection("system.serviceModel/client/endpoint");
section.SetAttributeValue("address", "net.tcp://192.168.0.1:123/MyService.svc");
server.CommitChanges();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.