Search code examples
wcftcpportsharing

how does my net.tcp wcf services work without specifying PortSharingEnabled in the binding?


I read all over the msdn where it says to enable port sharing : The port sharing service should be started and my net.tcp binding should specify 'portSharingEnabled = True'.

I also see that net.tcp binding documentation shows the default value for portsharing as false.

But in my VS 2013, WIN 7 machine, I have a console app hositing many services and I am able to run it from VS without any issues. My servichost is able to host more than 10 services with the same port. What am I missing to understand ? Any ideas ?

I use this endpoint followed by servicename for all my services:

   <service name="Lookup" behaviorConfiguration="">
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://localhost:8000/"/>
          </baseAddresses>
        </host>
        <endpoint 
                        name="IEntitiesLookup"
                        binding="netTcpBinding"
                        address="LookupService"
                        contract="ILookup" />
      </service>

Solution

  • I managed to clear my understanding on port sharing to an extent. But would be happy for more thoughts on this.

    I managed to find the reason behind the above scenario. Within a process, I am able to host several endpoints which shares the same port. This does not need port sharing to be enabled. But if I have another process which tries to host some services with same port numbers, then an exception for 'ports already in use' happens. In this case, we then need to enable port sharing in the binding of all the endpoints in both the service host processes and start the PortSharing service.

    I believe this boils down to the understanding that in the transport layer, the port numbers are tied to the process.