2010-05-11 56 views
18

我想将web.config中的system.serviceModel部分分隔成一个单独的文件以方便一些环境设置。我的努力没有结果。当我尝试使用这种方法。 WCF的代码抛出一个异常:“对于“的类型初始值System.ServiceModel.ClientBase 1抛出异常谁能告诉我什么,我做错了我可以将system.serviceModel分割成单独的.config文件吗?

Web.config文件:?

<configuration> 
    <system.serviceModel configSource="MyWCF.config" /> 
    .... 

MyWCF。配置:

<system.serviceModel> 
    <extensions> 
     ... 
    </extensions> 

    <bindings> 
     ... 
    </bindings> 

    <behaviors> 
     ... 
    </behaviors> 

    <client> 
     ... 
    </client> 

    </system.serviceModel> 

回答

32

你不能“外部化”的<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库或文档以找出答案。

你还应该在CodeProject上看看Jon Rista的.NET配置系统的三部分系列。

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

+1

不错的提示...这部分可以变得非常忙碌。 – JoeGeeky 2010-05-13 20:32:17

相关问题