roy_v

roy_v

  • NA
  • 13
  • 0

.NET Remoting

Oct 14 2003 5:49 PM
I have a Windows service that I have written that hosts a remotable object (a simple class with 3 or 4 methods.) I have another Windows service that serves as a client and accesses the remote object via an interface. Here is where my problem begins. Everything works great, with the exception of one thing. Once the remote object has been accessed, if I try to stop and restart the server, I get a "Service cannot be started. System.Net.Sockets.SocketException: Only one usage of each socket address (protocol/network address/port) is normally permitted at System.Runtime.Remoting.Channels.Tcp.TcpServerChannel.StartListening(Object data) at System.Runtime.Remoting.Channels.Tcp.TcpServerChannel.SetupChannel() at System.Runtime.Remoting.Channels.Tcp.TcpServerChannel..ctor(String name, Int32 port) at Publisher.PublisherService.OnStart(String[] args) at System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback(Object state)" Okay, now I know this means that essentially the TcpServerChannel could not be registered because something is either locking the port it is trying to bind to (port 2300), or garbage collection has not happened. After about 15minutes, the problem goes away, and I am able to start the service and the TcpServerChannel registers fine. The first thing I tried was to specify a System.String.Empty name for the TcpServerChannel, as the documentation specifed ...If you want to register more than one TcpServerChannel, each must have a unique name. Set this property to the Empty string ("") if you want to ignore names, but avoid naming collisions. The system will allow any number of channels with the String.Empty name". . But this did not work, for as soon as I accessed the remote object and then tried to restart the windows service, I get the same error as above. The next thing I tried was to force a GC.Collect in the OnStop event, but that did not work. The next thing I tried was to use netstat thinking that something is locking on to port 2300 and not letting go. I looked at "netstat -a" thinking that some process was locking the port, but nothing was locking the port. I checked via TaskManager to make sure my application was dead, and it is definitely dead. Now here is the shocker. I rebooted the box, and I still get the error, and the error only goes away after about approximately 10-15 minutes! Can anyone offer any suggestions, or anything else I can try to debug? Everything works wonderfully, no problems within the application or accessing the object or anything, but after the remote object is accessed, I cannot restart the application, until after approximately 10-15 minutes. Is this a GC issue?

Answers (12)