【问题标题】:Application Config Conundrum应用程序配置难题
【发布时间】:2009-08-12 17:00:48
【问题描述】:

我正在开发一个 n 层智能客户端应用程序。应用程序的客户端部分分为两层。接口应用程序和客户端业务库,用于检索数据并将其提供给接口。数据通过 WCF 服务 net.tcp 和 http 的集合提供,具体取决于客户端连接。

我的问题是接口对 wcf 服务一无所知(如我们所愿),配置 system.serviceModel 绑定信息存储在 lib 而不是 exe 的配置中。除非我将 system.serviceModel 部分复制到 exe 配置中,否则应用程序无法找到端点。

所以我可以创建一些 Pre-Build 事件来复制 app.config 文件:

attrib -r "$(ProjectDir)app.config" copy "$(SolutionDir)Domain\Client\app.config" "$(ProjectDir)"

但是,坦率地说,这是废话(它是直接复制而不是合并),我想要一种更好的工作方式...... 有任何想法吗? 谢谢

【问题讨论】:

  • 我之前也遇到过这个问题,但是忘记了我是怎么解决的:-)

标签: .net wcf smartclient


【解决方案1】:

您是否尝试过使用configSource 元素从外部配置文件中导入相关部分? last answer in this discussion 提供了可能适合您的解决方案。

引自该讨论:

<!-- WCF Configuration Mappings in app.config -->
<system.serviceModel>
  <bindings configSource=".\CommonConfig\ServiceBindings.config" />
  <client configSource=".\CommonConfig\ServiceClient.config" />
</system.serviceModel>

ServiceBindings.config:

<?xml version="1.0" encoding="utf-8" ?>
<bindings>
  <netTcpBinding>
    <binding ... />
  </netTcpBinding>
</bindings>

ServiceClient.config(缩短):

<?xml version="1.0" encoding="utf-8" ?>
<client>
  <endpoint ...>
      ...
  </endpoint>
</client>

【讨论】:

  • +1 很好的答案 - 这样,大部分配置也可以在服务器和客户端之间共享;毕竟,双方需要就绑定、(某些)行为和端点地址达成一致
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-03-19
  • 1970-01-01
  • 1970-01-01
  • 2023-03-17
  • 2010-09-06
  • 2014-10-04
  • 2010-12-12
相关资源
最近更新 更多