WCF (formerly Indigo), is the next generation way of developing distributed applications in .NET. Apart from being developed from Service Orientation perspective in mind and unifying all the distributed technologies of the Microsoft stack, it encompasses a variety of other features which either might not be highlighted or might be not been well documented. One among those features is the port sharing feature on TCP protocols. Organizations have NAT and firewalls for obvious security reasons. If any application that needs to be deployed and accessed across the firewall, one needs to rely on the common TCP ports that firewalls open. HTTP protocol normally uses Port 80. Thanks to the usage of HTTP.sys and IIS 6.0, wherein Port 80 can be used and shared across multiple applications, the problem is that there is not a single way in which we can enable port sharing via TCP.
What if the same port can be shared across multiple applications that run on TCP?
The answer to the same lies in the
NET.TCP Port Sharing feature of WCF. In this article, we will see how easily we can achieve the same in WCF.
What happens if same port is been used by applications running on TCP ?
In the above application, App 1 is running on TCP Port 2555 and client 1 is interacting with it. Now if Client 2 wants to access App 2 on the same port 2555, it will encounter the following error:
"There is already a listener on IP endpoint <Endpoint ID>. Make sure that you are not trying to use this endpoint multiple times in your application and that there are no other applications listening on this endpoint. "
NET.TCP Port sharing
NET.TCP Port sharing service, multiple applications in WCF can share the same ports.