I've seen similar questions here but couldn't find an answer. i have an app that uses WCF to open a connection to remote address, sometimes when i kill the app from the task manager or the app closes ungracefully the connection stays open and then when i restart my app i get an exception telling me there is already a listener on this port.
few questions :
- why such connections stay open after i kill the process?
- how can i close this connections when the process closes ungracefully?
- how can i close the connections before i try to create a new one?
serer side :
var url = Config.GetRemoteServerUrl();
var binding = new NetTcpBinding();
binding.Security.Mode = SecurityMode.None;
binding.ReliableSession.Enabled = Config.RelaiableSession;
binding.ReliableSession.InactivityTimeout = TimeSpan.MaxValue;
binding.MaxConnections = Config.MaxConcurrentSessions;
binding.ReaderQuotas.MaxArrayLength = Config.ReaderQuotasMaxArrayLength;
binding.MaxReceivedMessageSize = Config.MaxReceivedMessageSize;
binding.SendTimeout = new TimeSpan(0,0, 0, 0,Config.SendTimeout);
binding.OpenTimeout = new TimeSpan(0,0, 0, 0,Config.OpenTimeout);
host = new ServiceHost(ServerFacade.Instance, new Uri[] { new Uri(url) });
host.AddServiceEndpoint(typeof(ITSOServiceContract), binding, url);
host.Open();
serverFacade = host.SingletonInstance as IServerFacade;