The following is a snippet of the Windows host service app.config file.
<services> <service name="Share.Services.MainService"> <endpoint address="net.tcp://localhost:8001/MainService" behaviorConfiguration="netTcpBehavior" binding="netTcpBinding" contract="Share.Services.IClaimService" /> </service> <service name="Share.Services.MainMasterPageService"> <endpoint address="net.tcp://localhost:8001/MainMasterPageService" behaviorConfiguration="netTcpBehavior" binding="netTcpBinding" contract="Share.Services.IMainMasterpageService" /> </service> <service name="Share.Services.SMSService"> <endpoint address="net.tcp://localhost:8001/SMSService" behaviorConfiguration="netTcpBehavior" binding="netTcpBinding" contract="Share.ServiceContracts.Messaging.ISMSService" /> </service> </services>
There are 3 wcf services configured to use a TCP endpoint with port 8001. On a Windows service, I use the code below to register service hosts
private static ServiceHost[] Hosts = null; public static void Start() { try { while (!System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable()) { System.Threading.Thread.Sleep(1000); } BaseLog.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); Hosts = new ServiceHost[] { new ServiceHost(typeof(MainService)), new ServiceHost(typeof(MainMasterPageService)), new ServiceHost(typeof(SMSService)) }; foreach (ServiceHost host in Hosts) { RegisterServiceHost(host); } _log.Info("All Hosts Open"); } catch(Exception e) { _log.Error( "MainServiceHost", e); } }
For each ServiceHost object, I call the RegisterServiceHost function, the code of this function is below
public static void RegisterServiceHost(ServiceHost host) { var ops = (from e in host.Description.Endpoints from o in e.Contract.Operations select o).ToList(); ops.ForEach( operation => operation.Behaviors.Add(new MainContextOperationBehavior()) ); host.Open(); }
The code works without problems. My question is that all services use the same port 8001. How can all services share the same port. Even the Net.TCP Port Sharing Service is not enabled on the computer. My other question is that this will cause any performance impact when sharing the same port. IF I give a unique port, for example 8001,8002, 8003 for each service, then what is its advantage.
Sachin
source share