如何强制 net.tcp mex 端点 (mexTcpBinding) 参与端口共享?
我有一个作为 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
端点以及请求在该计算机上共享该端口的任何其他服务提供服务。
因此,看起来 mex 端点想要独占访问端口 808。我可以通过调整 mex 端点来解决这个问题,如下所示:
<endpoint
address="net.tcp://localhost:818/MyService/mex"
binding="mexTcpBinding"
contract="IMetadataExchange"
/>
这意味着 mex 端点现在拥有自己的独占端口。这样做的缺点是任何其他想要公开 mex 端点的服务也需要为其 mex 端点提供一个唯一的端口。这使得在寻找 mex 端点时变得非常不可预测。
有没有办法强制 mex 端点参与端口共享?
I have a WCF service which is hosted as a Windows Service. We would like to enable a mex endpoint at the same address (but with a '/mex' suffix). I have been trying to do this (unsuccessfully) using the following configuration:
<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>
When it runs, the service host throws an AddressAlreadyInUseException
complaining that "There is already a listener on IP endpoint 0.0.0.0:808". This actually makes sense to me because the port sharing service has opened that port in order to serve the MyService
endpoint along with any other services requesting to share that port on this machine.
So it seems that the mex endpoint wants exlusive access to port 808. I can work around this by tweaking the mex endpoint like so:
<endpoint
address="net.tcp://localhost:818/MyService/mex"
binding="mexTcpBinding"
contract="IMetadataExchange"
/>
This means that the mex endpoint now has its own exclusive port. The downside with this is that any other service which wants to expose a mex endpoint will also need a unique port for its mex endpoint. This makes it very unpredictable when looking for mex endpoints.
Is there a way to force the mex endpoint to participate in port sharing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
两个选项:
简单的方法:将 mex 点的整个绑定更改为 netTcpBinding 并让它重用您的绑定配置。 mexTCPBinding 只是为了方便,并且是可选的。如果它不适合您,请不要使用它。
困难的方法:您可以修改 mexTCPBinding 以启用共享。我见过的唯一示例是这里的代码: 链接
Two options:
The easy way: Change the entire binding for the mex point to netTcpBinding and have it reuse your bindingConfiguration. mexTCPBinding is only meant to be a convenience and is optional. If its not working for you, don’t use it.
The hard way: You can modify the mexTCPBinding to enable sharing. The only example I’ve seen is in code here: Link