问题描述
我想将web.config的system.serviceModel部分分成一个单独的文件,以方便进行某些环境设置.我的努力是徒劳的.当我尝试使用这种方法. wcf代码会引发异常:'System.ServiceModel.ClientBase 1
的类型初始化程序引发了异常.有人可以告诉我我在做什么错吗?
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:
Web.config:
<configuration>
<system.serviceModel configSource="MyWCF.config" />
....
MyWCF.config:
MyWCF.config:
<system.serviceModel>
<extensions>
...
</extensions>
<bindings>
...
</bindings>
<behaviors>
...
</behaviors>
<client>
...
</client>
</system.serviceModel>
推荐答案
您不能外部化" <system.serviceModel>
节组-因为它是配置节 group -但您可以肯定地将每个外部化其中的位:
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>
在.NET配置系统中, any 配置节可以被外部化-每个配置节都具有configSource
属性(即使Visual Studio有时会抱怨并声称相反.....) -但没有配置部分组.
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.
不幸的是,很难将这两个区分开来-您需要查阅MSDN库或文档来查找.
Unfortunately, these two are hard to tell apart - you need to consult the MSDN library or documentation to find out.
您还应该在CodeProject上查看Jon Rista在.NET配置系统上的三部分系列文章.
You should also check out Jon Rista's three-part series on the .NET configuration system up on CodeProject.
- Unraveling the mysteries of .NET 2.0 configuration
- Decoding the mysteries of .NET 2.0 configuration
- Cracking the mysteries of .NET 2.0 configuration
强烈推荐,写得很好并且非常有帮助!
Highly recommended, well written and extremely helpful!
这篇关于我可以将system.serviceModel拆分为单独的.config文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!