【发布时间】:2010-09-17 16:32:10
【问题描述】:
在托管多个 WCF 服务的应用程序中,为每个服务添加自定义配置信息的最佳方式是什么?例如,您可能想要传递或设置公司名称或指定连接字符串服务或其他一些参数。
我猜这可能通过实现 IServiceBehavior 来实现。
即类似....
<behaviors>
<serviceBehaviors>
<behavior name="MyBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug />
<customBehavior myCompany="ABC" />
</behavior>
<behavior name="MyOtherBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug />
<customBehavior myCompany="DEF" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="MyBehavior" name="MyNameSpace.MyService">
<endpoint address="" behaviorConfiguration="" binding="netTcpBinding"
name="TcpEndpoint" contract="MyNameSpace.IMyService" />
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
name="TcpMexEndpoint" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:4000/MyService" />
</baseAddresses>
</host>
</service>
<service behaviorConfiguration="MyOtherBehavior" name="MyNameSpace.MyOtherService">
<endpoint address="" behaviorConfiguration="" binding="netTcpBinding"
name="TcpEndpoint" contract="MyNameSpace.IMyOtherService" />
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
name="TcpMexEndpoint" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:4000/MyOtherService" />
</baseAddresses>
</host>
</service>
</services>
会在 MyService 上设置 ABC,在 MyOtherService 上设置 DEF(假设它们有一些带有公司名称的通用接口)。
谁能详细说明你是如何实现的?
TIA
迈克尔
【问题讨论】: