加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

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

发布时间:2020-12-15 23:50:06 所属栏目:asp.Net 来源:网络整理
导读:我想将web.config中的system.serviceModel部分分成一个单独的文件,以方便一些环境设置.我的努力没有结果.当我尝试使用这种方法. wcf代码引发异常:“System.ServiceModel.ClientBase 1的类型初始化程序抛出异常,有谁能告诉我我做错了什么? Web.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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读