【发布时间】:2011-02-03 08:08:30
【问题描述】:
我想分离我的 app.config 文件。例如,我想将 ServiceModel 部分移动到同一项目中的另一个配置文件中。我该怎么做?
谢谢。
【问题讨论】:
标签: c# app-config
我想分离我的 app.config 文件。例如,我想将 ServiceModel 部分移动到同一项目中的另一个配置文件中。我该怎么做?
谢谢。
【问题讨论】:
标签: c# app-config
您应该能够将configSource 属性设置为第二个文件(相对于第一个文件)的空元素。请参阅此处了解如何启用它for custom sections。
【讨论】:
我找到了路。我像这样更改了标签。
<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>
我在 Bindings、Behaviors、Extensions.config 文件中所做的相同。
它有效
【讨论】:
使用这样的东西:
<?xml version="1.0"?>
<configuration>
<appSettings />
<connectionStrings/>
<system.web>
<compilation debug="false" strict="false" explicit="true" />
</system.web>
<appSettings file="externalSettings.config"/>
</configuration>
【讨论】:
据我所知,这很遗憾是不可能的。
您可以做的是(如果我们谈论的是 WCF 代理)在您的代码中创建和配置您的代理。这样你就不需要 serviceModel 部分了。
现在只需为您需要的数据定义您自己的自定义部分,然后可以将其放在您的配置文件之外。
【讨论】: