WCF configuration files can sometimes be very, very long. And there’s a good reason for that too: WCF makes heavy use of configuration so that you can do just about anything you can do with code in a config file. I recently decided to estimate how much of the entire framework’s configuration belongs to WCF by looking at what percentage of the framework’s schema is under system.serviceModel, system.runtime.serialization, and system.serviceModel.activation. It turns out those section groups alone account for more than 70% of the entire framework’s configuration schema.
So even more so than for other section groups, it’s useful to be able to break up a long WCF configuration file into smaller, more manageable files. You can do this using the “configSource” attribute. It allows you to reference another file that contains the configuration section you declared.
So instead of having the following in your App.config:
<configuration>
<system.serviceModel>
<services>
<servicename="Service.EchoService"behaviorConfiguration="EchoServiceBehavior">
<endpointaddress =""binding="basicHttpBinding"contract="Service.IEcho"/>
<endpointaddress="mex"binding="mexHttpBinding"contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behaviorname="EchoServiceBehavior">
<serviceMetadatahttpGetEnabled="True" />
<serviceDebugincludeExceptionDetailInFaults="True" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
You could have the following in your App.config:
<configuration>
<system.serviceModel>
<services>
<servicename="Service.EchoService"behaviorConfiguration="EchoServiceBehavior">
<endpointaddress =""binding="basicHttpBinding"contract="Service.IEcho"/>
<endpointaddress="mex"binding="mexHttpBinding"contract="IMetadataExchange"/>
</service>
</services>
<behaviorsconfigSource="behaviors.config" />
</system.serviceModel>
</configuration>
And this in behaviors.config:
<behaviors>
<serviceBehaviors>
<behaviorname="EchoServiceBehavior">
<serviceMetadatahttpGetEnabled="True" />
<serviceDebugincludeExceptionDetailInFaults="True" />
</behavior>
</serviceBehaviors>
</behaviors>
If you wanted you could separate out your entire system.serviceModel section group into smaller files:
<configuration>
<system.serviceModel>
<servicesconfigSource="services.config"/>
<bindingsconfigSource="bindings.config"/>
<behaviorsconfigSource="behaviors.config"/>
<extensionsconfigSource="extensions.config"/>
</system.serviceModel>
</configuration>
Note, however, that you can only use this for sections. This technique can’t be used for the system.serviceModel section group or for any config elements. Also note that the referenced files should contain only one section, and that you won’t need a <configuration> or <system.serviceModel> tag in them, just the section being referenced.
Referenced from: http://blogs.msdn.com/b/youssefm/archive/2009/11/03/separating-out-wcf-configuration-into-multiple-files-with-configsource.aspx
本文介绍如何使用configSource属性将Windows Communication Foundation (WCF)配置文件拆分为更小、更易于管理的部分。通过这种方法可以显著提高大型项目的可维护性。

被折叠的 条评论
为什么被折叠?



