Web.Config,系统.serviceModel的外部文件

23

使用VS2010

我在我的web.config文件中有以下内容(细节已删除)。

<system.serviceModel>
    <behaviors />
    <services />
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
    <bindings />
    <client />
</system.serviceModel>

我希望能像appSettings一样使用configSource属性,从另一个配置文件中获取这些元素的详细信息。

我已经尝试将configSource属性应用于system.serviceModel或每个子节点中的任何一个,但是我收到了无效的蓝色波浪线,并显示:

The 'configSource' attribute is not allowed

我参考了这个问题中的第二个答案(Tom Brothers提供),它演示了我想要的内容。
能否从外部xml文件读取web.config?

附加信息
这是该帖子中的配置。具有无效的蓝色波浪线。

<connectionStrings configSource="web\config\connectionStrings.config" /> 
<appSettings configSource="web\config\appSettings.config" /> 
<system.diagnostics configSource="web\config\diagnostics.config" /> 
<system.serviceModel> 
    <bindings configSource="web\config\serviceModelBindings.config" /> 
    <behaviors configSource="web\config\serviceModelBehaviors.config" /> 
    <services configSource="web\config\serviceModelServices.config" /> 
    <client configSource="web\config\serviceModelClient.config" /> 
</system.serviceModel> 

在这种情况下,我该如何使用configSource属性?


1
你不能将configSource应用于system.serviceModel,因为它是一个配置节组。你是如何将configSource应用于底层节点的?能否包含一下这个样子,以便我们可以看到生成错误的配置文件? - David Hoerster
@David Hoerster:我也没有成功地应用到底层节点。虽然链接的文章建议这样做,但我无法让它起作用。我已经调整了我的帖子,展示了那篇帖子的答案。 - Valamas
是的,这确实是Visual Studio的一个缺陷。因此,如果您使用它,您将不得不在VS中一直面对永久性警告。 - Abacus
1个回答

34
由于<system.serviceModel>是配置节组而不是简单的配置部分,因此无法将configSource=应用于它。 只有简单的配置部分才提供configSource属性。
但是,您确实可以应用configSource属性到<system.serviceModel>中的任何一个节点-我经常在生产系统中这样做,并且它能正常工作。 您是否真的尝试过??
或者您让Visual Studio吓到了...它可能会通过那些波浪线向您显示(并告诉您)configSource="...."不允许(但这只是Visual Studio编辑器的缺陷)。在<system.serviceModel>的子节点上,可以使用configSource=属性!
您可以通过编辑原始问题来展示您的serviceModelBehaviors.config文件是什么样子的??
此外:该文件是否物理上位于您的Web应用程序的web\config子目录中?

2
我在使用Visual Studio 2010时遇到了问题,它告诉我bindingsclient子元素的configSource是“不允许”的,但就我所知,Visual Studio 2010编辑器是错误的。 - Jez
2
我在VS2012上仍然遇到这个问题。 - gverdouw
2
仍然在VS2013中遇到此问题。 - Dr Rob Lang
刚在VS2013中检查过。 - Dr Rob Lang
1
在VS2015中出现了同样的警告。微软加油! - SubliemeSiem
显示剩余3条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接