微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

wcf – 我可以将system.serviceModel分成一个单独的.config文件吗?

我想将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>

解决方法

您不能“外部化”< 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库或文档来了解.

您还应该查看Jon Rista在CodeProject上.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

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

原文地址:https://www.jb51.cc/aspnet/250929.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐