0

I'm having a bit of grief trying to modify my web applications web.config file using the Microsoft.Web.Administration.ServerManager library.

What I am trying to do is modify the client section located in System.ServiceModel.

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

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.

Maxim Gershkovich
  • 45,951
  • 44
  • 147
  • 243

1 Answers1

0

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();
  }
Will
  • 1
  • 2