Exception on System.ServiceModel.AddressAlreadyInUseException (ChannelListener)
I have an application which tries to host WCF service in a separate process.
So in my application, in the main process it has WCF service (called MainService), then in MainService, it starts another service by creating new Process() and the executable in the children process will use ServiceHost() to create a new WCF service.
When the MainService is stopped by using ServiceHost.Close(), and I use "netstat -a" at commandline and I saw the tcp listener for the MainService port is still alive. However, if I kill all child processes, then it's gone. If I don't kill the child process, and I try to restart the MainService, I will get error:
System.ServiceModel.AddressAlreadyInUseException: There is already a listener on IP endpoint 0.0.0.0:10100. Make sure that you a
re not trying to use this endpoint multiple times in your application and that there are no other applications listening on this e
ndpoint. > System.Net.Sockets.SocketException: Only one usage of each socket address (protocol/network address/port) is normall
y permitted
at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.Sockets.Socket.Bind(EndPoint localEP)
at System.ServiceModel.Channels.SocketConnectionListener.Listen()
End of inner exception stack trace
at System.ServiceModel.Channels.SocketConnectionListener.Listen()
at System.ServiceModel.Channels.BufferedConnectionListener.Listen()
at System.ServiceModel.Channels.ExclusiveTcpTransportManager.OnOpen()
at System.ServiceModel.Channels.TransportManager.Open(TransportChannelListener channelListener)
at System.ServiceModel.Channels.TransportManagerContainer.Open(SelectTransportManagersCallback selectTransportManagerCallback)
at System.ServiceModel.Channels.TransportChannelListener.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.ConnectionOrientedTransportChannelListener.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.TcpChannelListener`2.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open()
at IGT.SB.FAC.SCServiceImplementation.ServiceControllerAssistant.OnActivate()
5/16/2007 7:12:35 AM: IGT.SB.FAC.Executable.ServiceControllerApplication.Start
Service Controller failed to start.
Error: System.ServiceModel.AddressAlreadyInUseException: There is already a listener on IP endpoint 0.0.0.0:10100. 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. > System.Net.Sockets.SocketException: Only one usage of each socket address (protocol/network address/port) is n
ormally permitted
at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.Sockets.Socket.Bind(EndPoint localEP)
at System.ServiceModel.Channels.SocketConnectionListener.Listen()
End of inner exception stack trace
at System.ServiceModel.Channels.SocketConnectionListener.Listen()
at System.ServiceModel.Channels.BufferedConnectionListener.Listen()
at System.ServiceModel.Channels.ExclusiveTcpTransportManager.OnOpen()
at System.ServiceModel.Channels.TransportManager.Open(TransportChannelListener channelListener)
at System.ServiceModel.Channels.TransportManagerContainer.Open(SelectTransportManagersCallback selectTransportManagerCallback)
at System.ServiceModel.Channels.TransportChannelListener.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.ConnectionOrientedTransportChannelListener.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.TcpChannelListener`2.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open()
at IGT.SB.FAC.SCServiceImplementation.ServiceControllerAssistant.OnActivate()
at IGT.SB.FAC.SCServiceImplementation.ServiceControllerAssistant.Activate()
at IGT.SB.FAC.SCServiceImplementation.ServiceControllerAssistant.Start()
at IGT.SB.FAC.Executable.ServiceControllerApplication.Start()
I don't know what I am doing wrong here. I don't know what I miss to set in WCF. I try to find something in WCF binding that match with SO_reuseAddr in winsock.
In WCF, how can I find out if any channel is already in used? or How can I set the channel listener to reuse the port without using portSharingEnable?
Thank very much in advance for all your help
Anna

