在单个端口上托管多个 TCP WCF 服务端点 [英] Hosting Multiple TCP WCF service Endpoints on single Port

查看:26
本文介绍了在单个端口上托管多个 TCP WCF 服务端点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Windows 服务中托管 3 个 WCF 服务.每个 WCF 服务包含多个端点.现在,我通过不同端口上的 TCP 绑定托管我的所有端点.有没有办法在同一端口上托管来自不同 wcf 服务的所有这些端点?

I am hosting 3 WCF services inside windows services.Each WCF service contains Multiple endpoints. Right now, i am host all my endpoints thru TCP binding on different ports. Is there any way to host all these end points from different wcf services on same port?

推荐答案

出于好奇,我刚刚研究了一下.我发现的行为看起来很奇怪,我几乎不想把它放在这里.但它在我的情况下有效,所以也许它对你做同样的事情:

I just looked into that, out of curiosity. The behavior I discovered seems so strange that I almost don't want to put it here. But it worked in my case, so maybe it's doing the same for you:

当我尝试使用 portSharingEnabled="True" 在同一个 net.tcp 端口上托管 2 个服务(即 2 个单独的 ServiceHost 实例)时,我收到 AddressAlreadyInUseExceptioncode> 在 netTcpBinding 上为两者设置.无论是否运行 Net.Tcp 端口共享服务,都会发生这种情况.即使我只启动其中一项服务,也会抛出异常(并且我通过 netstat 验证了机器上的同一个端口上没有其他侦听器,另外,我以提升的权限运行了应用程序).

I am getting the AddressAlreadyInUseException when I'm trying to host 2 services (i.e., 2 separate ServiceHost instances) on the same net.tcp port with portSharingEnabled="True" set on the netTcpBinding for both. That happens with or without the Net.Tcp Port Sharing Service running. The exception is thrown even if I only start one of the services (and I verified via netstat that there was no other listener on that same port on the machine, plus, I ran the app with elevated privileges).

现在,有趣的是,当我设置 PortSharingEnabled = False 时,AddressAlreadyInUseException 不会被抛出,但两个服务都完全正常工作!!再一次,无论是否运行端口共享服务.我什至可以从另一台机器成功连接到这些服务.

Now, the funny thing is, the AddressAlreadyInUseException is not thrown when I set PortSharingEnabled = False, and yet both services are fully working!! Once again, with or without the Port Sharing Service running. I could even successfully connect to those services from a different machine.

但是,需要注意的是,以上仅适用于在同一进程中托管服务的情况!如果我尝试启动另一个正在侦听同一端口但基地址不同的应用程序实例,它确实会崩溃.但我假设您将这 3 个 WCF 服务托管在同一个 Windows 服务中?

An important note to make, however, is that the above only applies if the services are hosted within the SAME PROCESS! It does blow up if I try to start another instance of the app that's listening on the same port, but a different base address. But I'm assuming you're hosting those 3 WCF services inside the same Windows Service?

所以,即使看起来不对,我的答案是禁用 PortSharingEnabled 并查看它是否适用于同一端口上的不同 BaseAddresses(前提是它们都在同一个进程中).

So, even though it doesn't seem right, my answer would be to disable PortSharingEnabled and see if it works with different BaseAddresses on the same port (provided they're all inside the same process).

这篇关于在单个端口上托管多个 TCP WCF 服务端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆