0

尝试使用该Microsoft.Web.Administration.ServerManager库修改我的 Web 应用程序 web.config 文件时,我感到有些悲伤。

我想要做的是修改client位于System.ServiceModel.

基本上我想参加这样的条目

<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>

并将其更改为

<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>

我已经能够尽可能地检索 SectionGroup

using (ServerManager server = new ServerManager())
{        
    var siteConfig = server.Sites.First().GetWebConfiguration();
    var clientSection = siteConfig.GetEffectiveSectionGroup().SectionGroups["system.ServiceModel"].Sections["client"];
}

但我完全不知道如何修改实际条目。

任何指导将不胜感激。

4

1 回答 1

0

您可以像这样修改属性:

 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();
  }
于 2014-02-10T01:48:17.097 回答