PDA

View Full Version : Dispose resources from remoting service(box)



aletz
10-25-2007, 09:22 PM
Hi,

Sorry for my english.

i create a windows service with spring.net, i installed this in a windows server 2003, the remoting service works fine (Send/Recive message queue), but when i stop the service from service management...it stops fine, but when i start the service again...this sendme a error like this....

"Error creating context 'spring.root': Remoting configuration failed with the exception 'System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Net.Sockets.SocketException: Sólo se permite un uso de cada dirección de socket (protocolo/dirección de red/puerto)\r\n at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)\r\n at System.Net.Sockets.Socket.Bind(EndPoint localEP)\r\n at System.Net.Sockets.TcpListener.Start(Int32 backlog)\r\n at System.Net.Sockets.TcpListener.Start()\r\n at System.Runtime.Remoting.Channels.ExclusiveTcpListe ner.Start(Boolean exclusiveAddressUse)\r\n at System.Runtime.Remoting.Channels.Tcp.TcpServerChan nel.StartListening(Object data)\r\n at System.Runtime.Remoting.Channels.Tcp.TcpServerChan nel.SetupChannel()\r\n at System.Runtime.Remoting.Channels.Tcp.TcpServerChan nel..ctor(IDictionary properties, IServerChannelSinkProvider sinkProvider, IAuthorizeRemotingConnection authorizeCallback)\r\n at System.Runtime.Remoting.Channels.Tcp.TcpChannel..c tor(IDictionary properties, IClientChannelSinkProvider clientSinkProvider, IServerChannelSinkProvider serverSinkProvider)\r\n --- End of inner exception stack trace ---\r\n at System.RuntimeMethodHandle._InvokeConstructor(Obje ct[] args, SignatureStruct& signature, IntPtr declaringType)\r\n at System.RuntimeMethodHandle.InvokeConstructor(Objec t[] args, SignatureStruct signature, RuntimeTypeHandle declaringType)\r\n at System.Reflection.RuntimeConstructorInfo.Invoke(Bi ndingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)\r\n at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)\r\n at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)\r\n at System.Runtime.Remoting.RemotingConfigHandler.Crea teChannelFromConfigEntry(ChannelEntry entry)\r\n at System.Runtime.Remoting.RemotingConfigHandler.Conf igureChannels(RemotingXmlConfigFileData configData, Boolean ensureSecurity)\r\n at System.Runtime.Remoting.RemotingConfigHandler.Conf igureRemoting(RemotingXmlConfigFileData configData, Boolean ensureSecurity)'."


I think that the remoting service port still keep alive

<system.runtime.remoting>
<application>
<channels>
<channel ref="tcp" port="8005"/>
</channels>
</application>
</system.runtime.remoting>

when i stoped the service, the windows service calls the OnStop method and i dispose the context like this..

this.ctx.Dispose();
this.ctx = null;

but the port doesnt close...

do u have an idea???

Thank you in advance

aletz
10-26-2007, 12:08 AM
in this article...maybe has the solution...
http://blogs.msdn.com/dgorti/archive/2005/09/18/470766.aspx

sometime at restart the service works and other doesnt....

this is a part from my code:

<system.runtime.remoting>
<application>
<channels>
<channel ref="tcp" port="8005"/>
</channels>
<lifetime leaseTime="1S" renewOnCallTime="1S" leaseManagerPollTime="100MS" />
</application>
</system.runtime.remoting>

so..i need release the port when stop or restart the windows service .... and when teh windows service starts again, it works fine without the port error. Someone has an idea???

aletz
10-26-2007, 06:40 PM
the Ports are unmanaged resources and require explicit cleanup.
so.... in dispose method from the windows service...wrote this....

IChannel[] myIChannelArray = ChannelServices.RegisteredChannels;
for (int i = 0; i < myIChannelArray.Length; i++) System.Runtime.Remoting.Channels.ChannelServices.U nregisterChannel(myIChannelArray[i]);


and now, my windows service is restarted without problems!!

lahma
10-31-2007, 09:28 PM
The error you get is caused by registering remoting channels more than once (you probably had that figured out already). There seems to be no implementation to clean remoting infrastructure when shutting down but is should be done automatically when the application stops. Could there be some code that is kept running when you start the app again?

Maybe Bruno has an idea whether there could be some explicit cleanup of remoting.

Cheers,

-Marko