简体   繁体   English

使用Microsoft.Web.Administration.ServerManager修改web.config system.ServiceModel / client / endpoint

[英]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.ServiceModelclient部分。

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.

相关问题 Web.config错误(system.serviceModel) - Web.config error (system.serviceModel) Web.Config,system.serviceModel的外部文件 - Web.Config, external file for system.serviceModel 是否可以查看/编辑内部的WCF配置 <system.Servicemodel> 在web.config中的ASP .Net Web应用程序通过IIS管理器中的用户界面? - Is it possible to view / edit WCF configuration inside <system.Servicemodel> in web.config ASP .Net web application by user interface in IIS Manager? 来自Linux的.Net Core Microsoft.Web.Administration ServerManager - .Net Core Microsoft.Web.Administration ServerManager from Linux System.ServiceModel引用 - System.ServiceModel References System.ServiceModel消失 - System.ServiceModel disappear System.ServiceModel缺失 - System.ServiceModel missing 为什么尝试从Microsoft.Web.Administration连接ServerManager时出现COMException? - Why Am I getting COMException while trying to connect ServerManager from Microsoft.Web.Administration? 在 Windows 8.1 上访问 Microsoft.Web.Administration.ServerManager.Site 时出现 UnauthorizedAccessException - UnauthorizedAccessException while accessing Microsoft.Web.Administration.ServerManager.Site on Windows 8.1 为什么是<system.servicemodel> app.config 中缺少部分?</system.servicemodel> - Why is the <system.serviceModel> section missing from app.config?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM