2010-04-01 95 views
7

我想分開我的app.config文件。例如,我想將ServiceModel部件移動到同一項目中的另一個配置文件。我怎樣才能做到這一點?多個App.Config文件

謝謝。

回答

5

您應該可以擁有一個空元素並將configSource屬性設置爲第二個文件(相對於第一個文件)。看到這裏如何啓用它for custom sections

1

據我所知,這是可悲的是不可能的。

你可以做的是(如果我們正在談論WCF代理)在代碼中創建和配置代理。這樣你就不需要serviceModel部分。

現在只需爲您需要的數據定義您自己的自定義部分,然後就可以將其放置在配置文件之外。

2

使用這樣的事情:

<?xml version="1.0"?>  
<configuration>  
    <appSettings />  
    <connectionStrings/>  
    <system.web>  
     <compilation debug="false" strict="false" explicit="true" />  
    </system.web>  
    <appSettings file="externalSettings.config"/>  
</configuration> 
2

我找到了辦法。我改變了這個標籤。

<system.serviceModel> 
    <behaviors configSource="Behaviors.config"> 
    </behaviors> 
    <services configSource="Services.config"> 
    </services> 
    <bindings configSource="Bindings.config"> 
    </bindings> 
    <extensions configSource="Extensions.config"> 
    </extensions> 
    </system.serviceModel> 

後,我創建了Services.config文件和他們的,我把這個

<services> 
    <service behaviorConfiguration="ServiceBehavior" name="EntLib31ExceptionTest.Service1"> 
    <host> 
     <baseAddresses> 
     <add baseAddress="http://localhost:8001/ValidationService1/" /> 
     </baseAddresses> 
    </host> 
    <endpoint address="" 
       binding="wsHttpBinding" 
       bindingConfiguration="CustomBinding" 
       contract="EntLib31ExceptionTest.IService"  
       behaviorConfiguration="Validation"/> 
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
    </service> 
</services> 

同我在綁定,行爲,Extensions.config文件來完成。

和它的作品

+0

@Wilson:你需要學會如何突出你的代碼或XML行,並按編輯器工具欄上的「代碼」按鈕(101 010)給他們很好的格式 - 沒有凌亂的「<客戶端」如果你只記得將這些東西格式化爲代碼,就需要進行破解 – 2010-04-01 12:59:55