HighTechTalks DotNet Forums  

Singleton .Net Remoting and Lifetime Issue

Dotnet Framework (Remoting) microsoft.public.dotnet.framework.remoting


Discuss Singleton .Net Remoting and Lifetime Issue in the Dotnet Framework (Remoting) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
arnie
 
Posts: n/a

Default Singleton .Net Remoting and Lifetime Issue - 10-05-2007 , 09:45 AM






Hi all
There is a singleton .net remoting with lifetime issue and lease
renewal question in c# 2005?
I have created a simple class library with a single class that
inherits MarshalByRefObject and some functions besides
InitializeLifetimeService which is as given below:-


Code:
public override object InitializeLifetimeService()
{
ILease lease = (ILease)base.InitializeLifetimeService();

//Set lease properties
lease.InitialLeaseTime = TimeSpan.FromSeconds(3600);
lease.RenewOnCallTime = TimeSpan.FromSeconds(3);
lease.SponsorshipTimeout = TimeSpan.FromSeconds(10);
return lease;
}

I then compiled this class and then added the .dll to a very simple
asp .net 2.0 website. Inside Global.asax's Application_onStart, I have
written the below given code:-


Code:
BinaryServerFormatterSinkProvider bserver = new
BinaryServerFormatterSinkProvider();
bserver.TypeFilterLevel =
System.Runtime.Serialization.Formatters.TypeFilter Level.Full;
BinaryClientFormatterSinkProvider bClient = new
BinaryClientFormatterSinkProvider(); ;
System.Collections.IDictionary objDict = new
System.Collections.Hashtable();
objDict["port"] = 9993;
//ServChannel is a globally declared object in Global.asax
with type TcpChannel
ServChannel = new TcpChannel(objDict, bClient, bserver);
ChannelServices.RegisterChannel(ServChannel);


RemotingConfiguration.RegisterWellKnownServiceType (typeof(RemoteObj),
"RemoteObj", WellKnownObjectMode.Singleton );



I then created a simple window applicatioin in whose Form_Load, I have
written the below given code:-

Code:

BinaryServerFormatterSinkProvider bserver = new
BinaryServerFormatterSinkProvider();
bserver.TypeFilterLevel =
System.Runtime.Serialization.Formatters.TypeFilter Level.Full;
BinaryClientFormatterSinkProvider bClient = new
BinaryClientFormatterSinkProvider(); ;

TcpChannel ServChannel = new TcpChannel(null, bClient,
bserver);
ChannelServices.RegisterChannel(ServChannel);
objSponsor = new SponsorshipManager();
//objTest is the remoting class's object reference
objTest =
(RemoteObj.RemoteObj)Activator.GetObject(typeof(Re moteObj.RemoteObj),
"tcp://localhost:9993/RemoteObj");


Inside the form_load after above lines of code, I register the
Sponsorship using
objSponsor.Register(objTest);
where objTest is an object of type SponsorshipManager class that
resides in window application and that registers the remote object for
sponsorship its code is:-


Code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Serialization;
using System.Runtime.Remoting.Lifetime;

namespace Host
{
public class SponsorshipManager:MarshalByRefObject,ISponsor
{
TimeSpan ISponsor.Renewal(ILease lease)
{
return lease.InitialLeaseTime;
}
public void Register(MarshalByRefObject obj)
{
try
{
ILease lease =
(ILease)RemotingServices.GetLifetimeService(obj);
if (lease.CurrentState == LeaseState.Active)
{
lease.Register(this);
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
}
}


My problem is that after specified lease time expires the lease
renewal is not being called?
What's going wrong with this? Any idea?
Thanks
Parvez


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.