2011-03-02 34 views
19

外部文件中使用VS2010Web.Config中,對於system.serviceModel

我在我的web.config以下(詳細移除)。

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

我想用屬性configSource一樣的appSettings可以用它來獲取其它配置文件,這些元素的細節。

我試圖將configSource屬性應用於system.serviceModel或每個子節點。 不過,我得到無效的藍色wavvy行說:

The 'configSource' attribute is not allowed 

我這個問題,這證明我想什麼指第二個答案(由湯姆·兄弟)。
Can a web.config read from an external xml file?

附加
下面是從柱的配置。有無效的藍色曲折線。

<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 attibute?

+1

那麼,你不能將configSource應用到system.serviceModel,因爲它是一個配置節組。你是如何將configSource應用於底層節點的?你能否包含那些看起來像這樣我們可以看到生成錯誤的配置文件? – 2011-03-02 03:31:03

+0

@David Hoerster:我還沒有成功或者(適用於底層節點)。鏈接的文章暗示它,但我無法實現它的工作。我調整了我的帖子以顯示該帖子的答案。 – 2011-03-02 04:09:17

+0

是的,這確實是Visual Studio的失敗。所以如果你使用這個,你將不得不忍受VS中的永久警告。 – Abacus 2013-07-29 20:49:37

回答

29

不能適用於configSource=因爲<system.serviceModel>這是一個配置部分 - 不是簡單的配置節,和configSource屬性只在簡單的配置部分可用。

但是,您應該完全可以將configSource屬性應用於<system.serviceModel>內部的任何節點 - 我始終在生產系統中執行此操作 - 並且它正常工作。你甚至真的嘗試過? (或者告訴你)configSource="...."不被允許(通過那些波浪式的下劃線) - 但這只是Visual Studio編輯器中的一個缺點 - 在<system.serviceModel>的子節點上,它允許有一個configSource=屬性!

你能告訴我們(通過編輯你的原始問題)你的例如serviceModelBehaviors.config看起來像?

此外:該文件物理上在您的Web應用程序的web\config子目錄?

+4

遙不可及,Visual Studio把我嚇跑了!它工作,謝謝。 – 2011-03-02 11:35:30

+1

我得到的Visual Studio 2010告訴我,configSource對於'system.serviceModel'的''bindings''和'client'子元素是「不允許的」;據我所知,Visual Studio 2010編輯器是錯誤的。 – Jez 2013-09-09 09:52:27

+2

我仍然在VS2012上得到這個 – gverdouw 2013-09-10 02:00:03

相關問題