我有一个作为Windows服务托管的WCF服务。我们希望在同一地址启用一个mex端点(但后缀为“/mex”)。我一直在尝试使用以下配置执行此操作(未成功):
<system.serviceModel>
<services>
<service
name="MyCompany.MyService"
behaviorConfiguration="defaultServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost"/>
</baseAddresses>
</host>
<endpoint
address="MyService"
binding="netTcpBinding"
contract="MyCompany.IMyService"
bindingConfiguration="netTcpBindingConfig"
/>
<endpoint
address="MyService/mex"
binding="mexTcpBinding"
contract="IMetadataExchange"
/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="defaultServiceBehavior">
<serviceMetadata />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<netTcpBinding>
<binding name="netTcpBindingConfig" portSharingEnabled="true" />
</netTcpBinding>
</bindings>
</system.serviceModel>
AddressAlreadyInUseException
抱怨“IP端点0.0.0.0:808上已存在侦听器”。这实际上对我来说很有意义,因为端口共享服务已经打开了该端口,以便为
MyService
端点以及请求在此计算机上共享该端口的任何其他服务。
<endpoint
address="net.tcp://localhost:818/MyService/mex"
binding="mexTcpBinding"
contract="IMetadataExchange"
/>
这意味着mex端点现在有自己的独占端口。这样做的缺点是,任何其他想要公开mex端点的服务也需要为其mex端点提供一个唯一的端口。这使得在查找mex端点时非常不可预测。