2010-04-01 82 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