Cook Computing

Problem with Client Sponsor

July 14, 2004 Written by Charles Cook

I was asked to look into a remoting problem where objects were being disconnected even though sponsorship was implemented on the client. Instead of using the framework class ClientSponsor, a custom SponsorManager class had been developed which had additional methods such as UnregisterAll and which could be configured to specify that Dispose should be called during unregistration. In the context that this was being used it was a very useful class except that it didn't work - objects were being disconnected unexpectedly. I modified the code to use ClientSponsor and leasing started working as expected. I had a quick look at the ClientSponsor implementation using Reflector to check what was different and it immediately became obvious: ClientSponsor overrides InitializeLifetimeService to return null, thereby indicating that an infinite lease should be applied. Without this the default lease will be applied to the SponsorManager object, will never be renewed, and the object will eventually be disconnected. From this point onwards the server will be unable to call the sponsor object to renew leases and objects will start to be disconnected.


public override object InitializeLifetimeService()
{
    return null; 
}

Another point to note is that the client needs to register a channel so that the server can make the lease renewal calls.