Why is my C # Remoting object timeout even when Lifetime returns null?

This is the last resort after many days of searching on Google to try and find the final answer to my question.

I created a Windows service, a Windows form, and a Remoting object (all in C #). I am using a Remoting object to communicate between a service and a form using events.

Here's a simplified example of a typical interaction between objects:

  • AdminForm calls RemoteObject RequestLoadForm () method
  • RemoteObject fires an event that AdminService is listening
  • AdminService is notified of the event and calls LoadFormData (string data) in RemoteObject
  • RemoteObject fires an event that AdminForm is listening
  • AdminForm is notified of the event and can use string data to set values ​​in AdminForm elements

Everything works fine, everything interacts perfectly for the first 5 minutes or so. After that, the connection between the objects is somehow broken, and I can no longer communicate between the objects.

The first attempt to fix the problem was to overwrite the InitializeLifetimeService method to return null. This did not help (although this can avoid any future rental issues).

The second attempt was to make my AdminForm and AdminService ISponsors RemoteObject and configure them to extend the lease of the facility. Once again, the problem persists.

In my various googlings, I found that someone mentions something about event handlers that collect garbage. I am not sure if this is a problem or not, but I thought I would say that.

This is an error that appears after the connection has been idle for> 5 minutes:

System.Runtime.Remoting.RemotingException failed to process user code
Message = "The requested service was not found"
Source = "system.runtime.remoting"

Now it’s strange that this happens on the AdminService side. AdminForm calls the method on the remote object . This is a pop-up event, and then the AdminService sees this event and tries to call the RemoteObject LoadFormData method (string data), and this is where the exception is thrown.

I’m completely exhausted from Google searches, since I can’t find what I need to fix it.

+8
c # events remoting windows-services
source share
5 answers

I have a very similar problem. Hope for the following observation and solution for anyone who has a similar problem.

The presence of object A communicating with object B through the application domain, while object B will return object A through some event handlers. Both objects A and B inherit from MarshalByRefObject to enable callback through the application domain.

Object B overrides InitializeLifeTimeService to return null for endless leases. However, the connection still expired about 5 minutes (the default remote initial lease time) after starting the program.

The important point is that the call from object A will still succeed, but when object B turns back, the exception is a raise on object B. Apparently, the connection expired for the callback proxy of object A, and not on the contrary, as we thought.

Therefore, a quick answer, make sure that both objects A and B override InitializeLifeTimeService to return null. This will solve the problem, at least for my case.

Just some additional things when the connection has expired does not necessarily mean that the associated object is garbage collection. The lease term will disable the proxy server, but the actual object may still be present in the corresponding application domain. If you keep an equal rental period, if the object is GC'd, then it can dazzle you from viewing the entire image.

+3
source share

should be redefined:

public override object InitializeLifetimeService(){ return null; } 
+2
source share

You can set static properties in System.Runtime.Remoting.Lifetime.LifetimeServices on the server side:

 System.Runtime.Remoting.Lifetime.LifetimeServices.LeaseTime = TimeSpan.MaxValue; 

but I prefer to use leasing / sponsors (client side)

http://msdn.microsoft.com/en-us/library/6tkeax11.aspx

 MarshalByRefObject obj = remotingObject as MarshalByRefObject; ILease lease = (ILease)obj.GetLifetimeService(); MyClientSponsor sponsor = new MySponsor(); lease.Register(sponsor); 

If you have other sorting problems, use System.Runtime.Remoting.Services.TrackingServices namespace http://msdn.microsoft.com/en-us/library/system.runtime.remoting.services.trackingservices.aspx

+1
source share

You must overwrite the InitializeLifeTimeService () method not GetLifetimeService () to return null.

  public object InitializeLifetimeService(){ return null; } 

Then, if the object to be deleted has an infinite lifetime.

0
source share

This may have several reasons.

  • You may override InitializeLifetimeService on the wrong object. Find the source code for all MarshalByRef mentions and give everyone a long, hard look.

  • An endless lease lasts only until the application domain is unloaded. Find the source code for all Unload mentions and give everyone who unloads any AppDomain a long, hard look.

  • AppDomain could be restarted with the completion of the process, for example, restarting the Win32 service. It can also be downloaded by third-party code if your server is deployed to some application server, and some deployment or error recovery operations trigger a reboot; Examine third-party journals to find evidence of this.

  • Add enough registration and carefully examine the traces of the exception stack to be absolutely sure that you are not calling a third-party server object (perhaps through your own endless rental server object) or into an older version of your own code downloaded from someone who knows where, so researching the source code above might have skipped it.

I just finished investigating an incident that turned out to be a combination of the first and last item on my list.

0
source share

All Articles