本文介绍了我可以将 system.serviceModel 拆分为单独的 .config 文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Web.config:

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

MyWCF.config:

 ...</扩展名><绑定>...</绑定><行为>...</行为><客户>...</客户端></system.serviceModel>
解决方案

您不能外部化" 节组 - 因为它是一个配置节 group - 但你绝对可以将其中的每个位具体化:

<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 配置系统的三部分系列.

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

I want to separate my system.serviceModel section of the web.config into a separate file to facilitate some environment settings. My efforts have been fruitless. When I attempt it using this method. The wcf code throws an exception: "The type initializer for 'System.ServiceModel.ClientBase 1 threw an exception. Can anyone tell me what I am doing wrong?

Web.config:

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

MyWCF.config:

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

    <bindings>
      ...
    </bindings>

    <behaviors>
      ...
    </behaviors>

    <client>
       ...
    </client>

  </system.serviceModel>
解决方案

You cannot "externalize" the <system.serviceModel> section group - since it's a configuration section group - but you can definitely externalize each of the bits inside it:

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

In the .NET configuration system, any configuration section can be externalized - each configuration section has a configSource attribute (even though Visual Studio sometimes complains and claims the contrary.....) - but not configuration section groups.

Unfortunately, these two are hard to tell apart - you need to consult the MSDN library or documentation to find out.

You should also check out Jon Rista's three-part series on the .NET configuration system up on CodeProject.

Highly recommended, well written and extremely helpful!

这篇关于我可以将 system.serviceModel 拆分为单独的 .config 文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 09:58