我有一堆自托管的 WCF 服务。一切正常,但我正在寻找标准化/简化结果配置的方法。我已经尽可能地简化了它,但我仍然不高兴。目前,我的配置如下所示:
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="BindingConfiguration" ...>
...
</binding>
</netTcpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
...
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="ServiceBehavior" name="Name1">
<endpoint address="net.tcp://localhost:8080/name1" binding="netTcpBinding" bindingConfiguration="BindingConfiguration" contract="Contract1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</service>
<service behaviorConfiguration="ServiceBehavior" name="Name2">
<endpoint address="net.tcp://localhost:8080/name2" binding="netTcpBinding" bindingConfiguration="BindingConfiguration" contract="Contract2">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</service>
...
</services>
</system.serviceModel>
总之,我有 6 项服务,所以它是重复的。理想情况下,我想:
- 只指定一次“localhost:8080”并在所有服务之间共享,并且只指定差异(“name1”或“name2”)
- 只指定一次身份信息并在所有服务定义之间共享
首先,我知道base address,但这仅适用于服务级别,而不适用于单独的服务。对于我的第二点,我尝试将身份信息移动到端点行为中,但这似乎不受支持。
我能做些什么来简化这个配置吗?还是我唯一的选择是切换到基于代码的配置方法?