gpt4 book ai didi

wcf - 我可以将 system.serviceModel 拆分为单独的 .config 文件吗?

转载 作者:行者123 更新时间:2023-12-03 12:06:26 24 4
gpt4 key购买 nike

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

网络配置:

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

MyWCF.config:
  <system.serviceModel>
<extensions>
...
</extensions>

<bindings>
...
</bindings>

<behaviors>
...
</behaviors>

<client>
...
</client>

</system.serviceModel>

最佳答案

你不能“外部化”<system.serviceModel>节组 - 因为它是一个配置节组 - 但您绝对可以将其中的每个位外部化:

<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 配置系统中,任何配置节都可以外部化——每个配置节都有一个 configSource属性(即使 Visual Studio 有时会提示并声称相反......) - 但不是配置节组。

不幸的是,这两者很难区分——您需要查阅 MSDN 库或文档才能找到答案。

您还应该在 CodeProject 上查看 Jon Rista 关于 .NET 配置系统的三部分系列。
  • Unraveling the mysteries of .NET 2.0 configuration
  • Decoding the mysteries of .NET 2.0 configuration
  • Cracking the mysteries of .NET 2.0 configuration

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

    关于wcf - 我可以将 system.serviceModel 拆分为单独的 .config 文件吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2813975/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com