Remoting Exception

G

Guest

Hi,

I wrote a remoting object and published it like this:

public class RemoteLogger : MarshalByRefObject
{
// Contain some methods...
}

public class RemoteManager
{
private TcpChannel m_Channel = null;
private RemoteLogger m_RemoteLogger = null;

public void Initialize(string port)
{
// Registering the channel
BinaryClientFormatterSinkProvider clientProvider = null;
BinaryServerFormatterSinkProvider serverProvider = new
BinaryServerFormatterSinkProvider();
serverProvider.TypeFilterLevel = TypeFilterLevel.Full;
IDictionary APIprops = new Hashtable();
APIprops["port"] = port;
APIprops["name"] = "Logger";
APIprops["typeFilterLevel"] = TypeFilterLevel.Full;

m_Channel = new TcpChannel(port, clientProvider, serverProvider);
ChannelServices.RegisterChannel(m_Channel);

// Creating a normal local instance of Logger API object and Marshal it.
// This will register the EventsManager as a running singleton object.
// When the clients calls Activator.GetObject it will connect to this
running instance.
m_RemoteLogger = new RemoteLogger();
RemotingServices.Marshal(m_RemoteLogger, "MyLoggerUri");
}

Other application uses this remote logger fine, But after a while (only a
few minutes) of no activity with this remote logger, and then trying to use
any of its methods cause en exception throwing as follow:

"An unhandled exception of type 'System.Runtime.Remoting.RemotingException'
occurred in mscorlib.dll
Additional information: Requested Service not found"

As I understand my RemoteLogger life time should be infinite because it was
created by local new and the reference for it never released.



Can anybody tell what is the problem?

Should I add the InitializeLifetimeService() for the RemoteLogger to return
null?

If I do add the InitializeLifetimeService(), how can I free it manually by
code when the RemoteManager whishes to free it?
 
G

Guest

Hi,

All the Remote objects have a timeout, where they are destroyed if nobody
use them, in order to avoid this override the following function

public override object InitializeLifetimeService()
{
return null;
}

on your RemoteLogger class. This should work
Regards
Salva
 
G

Guest

If I do add the InitializeLifetimeService(), how can I free the remote object
manually by code when the RemoteManager whishes to free it?
 
G

Guest

Hi,

Where is your remote object? in a windows service? in a webservice? in a
console?

If is a Windows service you can do it stopping the service, manually or by
code.
If is a Webservice you can easily implement a function to dispose the remote
object
If is a console stopping tha app will free it.

Now, if you want to stop it automatically you need to define the Lease of
the object, remember that the Remoting is alive based on the following flow:

1) When the object is called the lease is renewed (it is sponsored)
2) A timer checks when all the sponsors are expired
3) If there are no sponsors the object is disposed
4) Otherwise continue

Check:

ILease lease = (ILease)base.InitializeLifetimeService();
if (lease.CurrentState == LeaseState.Initial)
{
lease.InitialLeaseTime = TimeSpan.FromMinutes(1);
lease.SponsorshipTimeout = TimeSpan.FromMinutes(2);
lease.RenewOnCallTime = TimeSpan.FromSeconds(2);
}

Hope this helps to understand


Overriding the InitializeLifeTime you are returning infinite timeout
 
G

Guest

I'm not sure I fully understand you.

my remote object is as I posted above.
It used inside a .NET DLL used in a Windows application.

Actually I want the remoting object to live during the whole life time of
the application.

So isn't enough just to add the just the InitializeLifetimeService(),
without any sponsor and disposing?
 
G

Guest

Hi,

Why do you use a remote object within the same appDomain?? Is the same as
using sockets within an app.

If is the same app the problem now is simple, return null on the
InitializeLifetimeService() and your remoting object will be disposed when
you end your application, once the RemoteManager is disposed the channel
registration will be dropped.

Regards
Salva
 
G

Guest

No, the local application is holding the remote object so OTHER applications
can invoke method at the local application using this remote object.

I hope I'm more clear now.

So...
If I want the remoting object to live during the whole life time of local
application.
isn't it enough just to add the InitializeLifetimeService() method so it
will return null, without any sponsor and disposing?
 
R

Richard Blewett [DevelopMentor]

Yes,

if its an object you ahve created and remoted via RemotingServices.Marshal or a wellknown singleton object then just return null from InitializeLifetimeServices. But don;t do this for client activated objects.

regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

So...
If I want the remoting object to live during the whole life time of local
application.
isn't it enough just to add the InitializeLifetimeService() method so it
will return null, without any sponsor and disposing?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top