Hosting Multiple TCP WCF service Endpoints on single Port

主宰稳场 提交于 2019-12-19 10:26:11

问题


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?


回答1:


Sure is! You can use the Net.TCP Port Sharing service.

Net.TCP Port Sharing on MSDN




回答2:


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:

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).

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.

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?

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).




回答3:


As far as I know you not only have to enable port sharing on the configuration (or via code), you also have to manually start the Windows Port Sharing service.

That's the reason why I (having similar problem) didn't want to use port sharing, to make it easier for deployment rather than having to mess with other things the user may or may not know.



来源:https://stackoverflow.com/questions/5889596/hosting-multiple-tcp-wcf-service-endpoints-on-single-port

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!