I have a Client and Server scenario, where a service is installed on the client and another service on the server. I have no issues when these are installed on different machines. However, I would like to also be able to install both the Client service and Server service on the same machine. I could set them up to use different ports, however I would like to accomplish this using a single port.
I have enabled and started the Net.Tcp Port Sharing Service Windows service. I start up the Server service first. When I attempt to start the Client service I get the following exception upon executing serviceHost.Open():
The TransportManager failed to listen on the supplied URI using the NetTcpPortSharing service: the URI is already registered with the service.
Below is the source code. Both Server and Client use different end point addresses as follows:
Server Service:
ServiceHost serviceHost = new ServiceHost(typeof(ServerService),
new Uri("net.tcp://localhost:50000");
NetTcpBinding binding = new NetTcpBinding();
serviceHost.AddServiceEndpoint(typeof(IServerService),
binding, "ServerService");
serviceHost.Open();
Client Service:
ServiceHost serviceHost = new ServiceHost(typeof(ClientService),
new Uri("net.tcp://localhost:50000");
NetTcpBinding binding = new NetTcpBinding();
serviceHost.AddServiceEndpoint(typeof(IClientService),
binding, "ClientService");
serviceHost.Open();