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

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

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....