【问题标题】:Can I split system.serviceModel into a separate .config file?我可以将 system.serviceModel 拆分为单独的 .config 文件吗?
【发布时间】:2017-10-04 20:34:55
【问题描述】:

我想将 web.config 的 system.serviceModel 部分分离到一个单独的文件中,以方便一些环境设置。我的努力没有结果。当我尝试使用这种方法时。 wcf 代码引发异常:“'System.ServiceModel.ClientBase 1 的类型初始化程序引发异常。谁能告诉我我做错了什么?

Web.config:

<configuration>
  <system.serviceModel configSource="MyWCF.config" />
  ....

MyWCF.config:

  <system.serviceModel>
    <extensions>
      ...
    </extensions>

    <bindings>
      ...
    </bindings>

    <behaviors>
      ...
    </behaviors>

    <client>
       ...
    </client>

  </system.serviceModel>

【问题讨论】:

    标签: wcf web-config asp.net-3.5


    【解决方案1】:

    你不能“外部化”&lt;system.serviceModel&gt; 部分组——因为它是一个配置部分——但你绝对可以外部化其中的每个位:

    <system.serviceModel>
        <behaviors configSource="behaviors.config" />
        <bindings configSource="bindings.config" />
        <extensions configSource="extensions.config" />
        <client configSource="client.config" />
        <services configSource="services.config" />
    </system.serviceModel>
    

    在 .NET 配置系统中,any 配置部分可以外部化 - 每个配置部分都有一个 configSource 属性(尽管 Visual Studio 有时会抱怨并声称相反.....) - 但不是配置节组。

    很遗憾,这两者很难区分 - 您需要查阅 MSDN 库或文档才能找到答案。

    您还应该在 CodeProject 上查看 Jon Rista 关于 .NET 配置系统的三部分系列。

    强烈推荐,写得很好,非常有帮助!

    【讨论】:

    • 不错的提示...这部分可能会很忙。
    【解决方案2】:

    【讨论】:

    • 谢谢,那篇文章中的示例比其他答案中的更完整。
    猜你喜欢
    • 1970-01-01
    • 2019-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-24
    • 2020-01-12
    • 1970-01-01
    • 2016-02-07
    相关资源
    最近更新 更多