【问题标题】:how to use AppSettings of app.config in itself如何使用 app.config 本身的 AppSettings
【发布时间】:2012-08-12 22:09:09
【问题描述】:

我在客户端有一个 wcf 配置。我需要在 AppSettings 中使用 ServerIP 的键来命名 App.Config 中的其他部分,而不是 localhost,因为我的端点数量很多而且我的服务器 ip 是可变的。我该怎么办?

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="ServerIP" value="localhost"/>
  </appSettings>

  <system.serviceModel>
    <bindings>
        ...
    </bindings>
    <client>

      <endpoint address="net.tcp://localhost:9000/WcfServices/Person/PersonService" 
        binding="netTcpBinding" bindingConfiguration="RCISPNetTcpBindingWpf"
        contract="Common.ServiceContract.IPersonService" name="BasicHttpBinding_IPersonService">
        <identity>
          <dns value="localhost" /> <!--How use ServerIP in appSettings instead of localhost-->
        </identity>
      </endpoint>           

    </client>
  </system.serviceModel>
</configuration>

【问题讨论】:

    标签: c# configuration app-config appsettings


    【解决方案1】:

    通常你不能这样做,但如果你使用 VisualStudio 2010,你也许可以使用web.config transformations。我认为你必须使用 web deploy,或者自己运行一个 MSBuild 任务来运行转换。

    【讨论】:

      【解决方案2】:

      您不能在 app.config 本身中使用 appsettings。 你有两种可能: - 通过代码使用 appsettings,例如制作我们的自定义部分 http://haacked.com/archive/2007/03/12/custom-configuration-sections-in-3-easy-steps.aspx - 使用带有占位符的 nant build 或 msbuild How to use MSbuild property in TransformXml task?

      【讨论】:

        猜你喜欢
        • 2015-06-05
        • 1970-01-01
        • 2011-12-12
        • 2011-10-18
        • 2018-11-09
        • 2016-01-19
        • 2011-12-17
        • 1970-01-01
        • 2011-09-13
        相关资源
        最近更新 更多