0

我在客户端有一个 wcf 配置。我需要在 AppSettings by ServerIPName 中为 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>
4

2 回答 2

0

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

于 2012-08-12T13:42:11.133 回答
0

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

于 2012-08-12T14:09:09.757 回答