[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.remoting

Remoted object is connectable even after disconnecting it...

TT

9/23/2004 4:13:00 PM

Hi there,

In my current project I have a logging utility that is a standalone app. The
utility shows log entries, other apps can connect to it and send logging
entries to be displayed.

I use RemotingServices.Marshal at startup of the log util to allow other
apps to access the logging utility. When the log util is closed, I use
RemotingServices.Disconnect to make the log app unavailable.

The problem is that even when I close my log util, clients can still connect
to the remoted (log-)object. I'll add some code to clarify. Class MyLog is a
MarshalByRefObject, which implements IMyLog which contains the real
interface. MyLog overrides InitializeLifetimeService method and returns null
as lease timeout.

<code>

// log-server startup:
// ---------------------
this.channel = new System.Runtime.Remoting.Channels.Tcp.TcpChannel (
this.config.Channel
);

System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel (
this.channel
);

this.myLog = new MyLog( this ); // the remoted object

System.Runtime.Remoting.RemotingServices.Marshal (
this.myLog,
this.config.MyLogURI,
typeof( IMyLog )
);

// log-server shutdown code:
// ------------------------------
if( this.myLog != null )
System.Runtime.Remoting.RemotingServices.Disconnect (
this.myLog
);

if( this.channel != null
)System.Runtime.Remoting.Channels.ChannelServices.UnregisterChannel(
this.channel );

// client connection code:
// --------------------------
string connectionStr = "tcp://" + this.config.Address + ":" +
this.config.Channel.ToString() + "/" +
this.config.MyLogURI;

object objref = System.Runtime.Remoting.RemotingServices.Connect (
typeof( IMyLog ),
connectionStr
);

this.myLog = objref as IMyLog;

</code>

So, even if my log app is closed and hence the shutdown code is run and the
remoted object should be dead, clients can still connect to it i.e. the
RemotingService.Connect call succeeds.

What am I doing wrong? Thanks for any help :)

Kind regards.
--
Tom Tempelaere.
5 Answers

Ken Kolda

9/23/2004 5:36:00 PM

0

The call to RemotingServices.Connect() does not actually cause a connection
to be made to the server -- it just creates a proxy. The actual connection
is made the first time you invoke a property or method on the proxy object.
At that point you should get an exception indicating that no connection can
be made to the server.

Ken


"TT (Tom Tempelaere)" <_|\|_0$P@|/\|titi____AThotmailD.Tcom|/\|@P$0_|\|_>
wrote in message news:090D8A15-9C01-43A4-A4B1-958DDCDACB9C@microsoft.com...
> Hi there,
>
> In my current project I have a logging utility that is a standalone app.
The
> utility shows log entries, other apps can connect to it and send logging
> entries to be displayed.
>
> I use RemotingServices.Marshal at startup of the log util to allow other
> apps to access the logging utility. When the log util is closed, I use
> RemotingServices.Disconnect to make the log app unavailable.
>
> The problem is that even when I close my log util, clients can still
connect
> to the remoted (log-)object. I'll add some code to clarify. Class MyLog is
a
> MarshalByRefObject, which implements IMyLog which contains the real
> interface. MyLog overrides InitializeLifetimeService method and returns
null
> as lease timeout.
>
> <code>
>
> // log-server startup:
> // ---------------------
> this.channel = new System.Runtime.Remoting.Channels.Tcp.TcpChannel (
> this.config.Channel
> );
>
> System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel (
> this.channel
> );
>
> this.myLog = new MyLog( this ); // the remoted object
>
> System.Runtime.Remoting.RemotingServices.Marshal (
> this.myLog,
> this.config.MyLogURI,
> typeof( IMyLog )
> );
>
> // log-server shutdown code:
> // ------------------------------
> if( this.myLog != null )
> System.Runtime.Remoting.RemotingServices.Disconnect (
> this.myLog
> );
>
> if( this.channel != null
> )System.Runtime.Remoting.Channels.ChannelServices.UnregisterChannel(
> this.channel );
>
> // client connection code:
> // --------------------------
> string connectionStr = "tcp://" + this.config.Address + ":" +
> this.config.Channel.ToString() + "/" +
> this.config.MyLogURI;
>
> object objref = System.Runtime.Remoting.RemotingServices.Connect (
> typeof( IMyLog ),
> connectionStr
> );
>
> this.myLog = objref as IMyLog;
>
> </code>
>
> So, even if my log app is closed and hence the shutdown code is run and
the
> remoted object should be dead, clients can still connect to it i.e. the
> RemotingService.Connect call succeeds.
>
> What am I doing wrong? Thanks for any help :)
>
> Kind regards.
> --
> Tom Tempelaere.


TT

9/24/2004 9:13:00 AM

0

Hi Ken,

I tested and indeed a TranparantProxy is made. How can I check whether the
remoted object is alive, without having to call a method I wrote? A sort of a
ping but then for the remoted object...

Thank you.
Tom T.


"Ken Kolda" wrote:

> The call to RemotingServices.Connect() does not actually cause a connection
> to be made to the server -- it just creates a proxy. The actual connection
> is made the first time you invoke a property or method on the proxy object.
> At that point you should get an exception indicating that no connection can
> be made to the server.
>
> Ken
>
>
> "TT (Tom Tempelaere)" <_|\|_0$P@|/\|titi____AThotmailD.Tcom|/\|@P$0_|\|_>
> wrote in message news:090D8A15-9C01-43A4-A4B1-958DDCDACB9C@microsoft.com...
> > Hi there,
> >
> > In my current project I have a logging utility that is a standalone app.
> The
> > utility shows log entries, other apps can connect to it and send logging
> > entries to be displayed.
> >
> > I use RemotingServices.Marshal at startup of the log util to allow other
> > apps to access the logging utility. When the log util is closed, I use
> > RemotingServices.Disconnect to make the log app unavailable.
> >
> > The problem is that even when I close my log util, clients can still
> connect
> > to the remoted (log-)object. I'll add some code to clarify. Class MyLog is
> a
> > MarshalByRefObject, which implements IMyLog which contains the real
> > interface. MyLog overrides InitializeLifetimeService method and returns
> null
> > as lease timeout.
> >
> > <code>
> >
> > // log-server startup:
> > // ---------------------
> > this.channel = new System.Runtime.Remoting.Channels.Tcp.TcpChannel (
> > this.config.Channel
> > );
> >
> > System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel (
> > this.channel
> > );
> >
> > this.myLog = new MyLog( this ); // the remoted object
> >
> > System.Runtime.Remoting.RemotingServices.Marshal (
> > this.myLog,
> > this.config.MyLogURI,
> > typeof( IMyLog )
> > );
> >
> > // log-server shutdown code:
> > // ------------------------------
> > if( this.myLog != null )
> > System.Runtime.Remoting.RemotingServices.Disconnect (
> > this.myLog
> > );
> >
> > if( this.channel != null
> > )System.Runtime.Remoting.Channels.ChannelServices.UnregisterChannel(
> > this.channel );
> >
> > // client connection code:
> > // --------------------------
> > string connectionStr = "tcp://" + this.config.Address + ":" +
> > this.config.Channel.ToString() + "/" +
> > this.config.MyLogURI;
> >
> > object objref = System.Runtime.Remoting.RemotingServices.Connect (
> > typeof( IMyLog ),
> > connectionStr
> > );
> >
> > this.myLog = objref as IMyLog;
> >
> > </code>
> >
> > So, even if my log app is closed and hence the shutdown code is run and
> the
> > remoted object should be dead, clients can still connect to it i.e. the
> > RemotingService.Connect call succeeds.
> >
> > What am I doing wrong? Thanks for any help :)
> >
> > Kind regards.
> > --
> > Tom Tempelaere.
>
>
>

TT

9/24/2004 9:27:00 AM

0

Hey Ken,

I noticed that the method I called does not throw any exception, even though
the log-app is not alive. Could that be due to the fact that my methods in
the interface (IMyLog) are OneWay?

Thanks,
Tom T.

"Ken Kolda" wrote:

> The call to RemotingServices.Connect() does not actually cause a connection
> to be made to the server -- it just creates a proxy. The actual connection
> is made the first time you invoke a property or method on the proxy object.
> At that point you should get an exception indicating that no connection can
> be made to the server.
>
> Ken
>
>
> "TT (Tom Tempelaere)" <_|\|_0$P@|/\|titi____AThotmailD.Tcom|/\|@P$0_|\|_>
> wrote in message news:090D8A15-9C01-43A4-A4B1-958DDCDACB9C@microsoft.com...
> > Hi there,
> >
> > In my current project I have a logging utility that is a standalone app.
> The
> > utility shows log entries, other apps can connect to it and send logging
> > entries to be displayed.
> >
> > I use RemotingServices.Marshal at startup of the log util to allow other
> > apps to access the logging utility. When the log util is closed, I use
> > RemotingServices.Disconnect to make the log app unavailable.
> >
> > The problem is that even when I close my log util, clients can still
> connect
> > to the remoted (log-)object. I'll add some code to clarify. Class MyLog is
> a
> > MarshalByRefObject, which implements IMyLog which contains the real
> > interface. MyLog overrides InitializeLifetimeService method and returns
> null
> > as lease timeout.
> >
> > <code>
> >
> > // log-server startup:
> > // ---------------------
> > this.channel = new System.Runtime.Remoting.Channels.Tcp.TcpChannel (
> > this.config.Channel
> > );
> >
> > System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel (
> > this.channel
> > );
> >
> > this.myLog = new MyLog( this ); // the remoted object
> >
> > System.Runtime.Remoting.RemotingServices.Marshal (
> > this.myLog,
> > this.config.MyLogURI,
> > typeof( IMyLog )
> > );
> >
> > // log-server shutdown code:
> > // ------------------------------
> > if( this.myLog != null )
> > System.Runtime.Remoting.RemotingServices.Disconnect (
> > this.myLog
> > );
> >
> > if( this.channel != null
> > )System.Runtime.Remoting.Channels.ChannelServices.UnregisterChannel(
> > this.channel );
> >
> > // client connection code:
> > // --------------------------
> > string connectionStr = "tcp://" + this.config.Address + ":" +
> > this.config.Channel.ToString() + "/" +
> > this.config.MyLogURI;
> >
> > object objref = System.Runtime.Remoting.RemotingServices.Connect (
> > typeof( IMyLog ),
> > connectionStr
> > );
> >
> > this.myLog = objref as IMyLog;
> >
> > </code>
> >
> > So, even if my log app is closed and hence the shutdown code is run and
> the
> > remoted object should be dead, clients can still connect to it i.e. the
> > RemotingService.Connect call succeeds.
> >
> > What am I doing wrong? Thanks for any help :)
> >
> > Kind regards.
> > --
> > Tom Tempelaere.
>
>
>

Ken Kolda

9/24/2004 3:12:00 PM

0

You will need to invoke some property or method to determine if the server
is still up. Using ToString() is often the easiest bet.

Ken


"TT (Tom Tempelaere)" <_|\|_0$P@|/\|titi____AThotmailD.Tcom|/\|@P$0_|\|_>
wrote in message news:68972BB8-FBFA-42CA-9978-4D717D94FA56@microsoft.com...
> Hi Ken,
>
> I tested and indeed a TranparantProxy is made. How can I check whether the
> remoted object is alive, without having to call a method I wrote? A sort
of a
> ping but then for the remoted object...
>
> Thank you.
> Tom T.
>
>
> "Ken Kolda" wrote:
>
> > The call to RemotingServices.Connect() does not actually cause a
connection
> > to be made to the server -- it just creates a proxy. The actual
connection
> > is made the first time you invoke a property or method on the proxy
object.
> > At that point you should get an exception indicating that no connection
can
> > be made to the server.
> >
> > Ken
> >
> >
> > "TT (Tom Tempelaere)"
<_|\|_0$P@|/\|titi____AThotmailD.Tcom|/\|@P$0_|\|_>
> > wrote in message
news:090D8A15-9C01-43A4-A4B1-958DDCDACB9C@microsoft.com...
> > > Hi there,
> > >
> > > In my current project I have a logging utility that is a standalone
app.
> > The
> > > utility shows log entries, other apps can connect to it and send
logging
> > > entries to be displayed.
> > >
> > > I use RemotingServices.Marshal at startup of the log util to allow
other
> > > apps to access the logging utility. When the log util is closed, I use
> > > RemotingServices.Disconnect to make the log app unavailable.
> > >
> > > The problem is that even when I close my log util, clients can still
> > connect
> > > to the remoted (log-)object. I'll add some code to clarify. Class
MyLog is
> > a
> > > MarshalByRefObject, which implements IMyLog which contains the real
> > > interface. MyLog overrides InitializeLifetimeService method and
returns
> > null
> > > as lease timeout.
> > >
> > > <code>
> > >
> > > // log-server startup:
> > > // ---------------------
> > > this.channel = new System.Runtime.Remoting.Channels.Tcp.TcpChannel (
> > > this.config.Channel
> > > );
> > >
> > > System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel (
> > > this.channel
> > > );
> > >
> > > this.myLog = new MyLog( this ); // the remoted object
> > >
> > > System.Runtime.Remoting.RemotingServices.Marshal (
> > > this.myLog,
> > > this.config.MyLogURI,
> > > typeof( IMyLog )
> > > );
> > >
> > > // log-server shutdown code:
> > > // ------------------------------
> > > if( this.myLog != null )
> > > System.Runtime.Remoting.RemotingServices.Disconnect (
> > > this.myLog
> > > );
> > >
> > > if( this.channel != null
> > > )System.Runtime.Remoting.Channels.ChannelServices.UnregisterChannel(
> > > this.channel );
> > >
> > > // client connection code:
> > > // --------------------------
> > > string connectionStr = "tcp://" + this.config.Address + ":" +
> > > this.config.Channel.ToString() +
"/" +
> > > this.config.MyLogURI;
> > >
> > > object objref = System.Runtime.Remoting.RemotingServices.Connect (
> > > typeof( IMyLog ),
> > > connectionStr
> > > );
> > >
> > > this.myLog = objref as IMyLog;
> > >
> > > </code>
> > >
> > > So, even if my log app is closed and hence the shutdown code is run
and
> > the
> > > remoted object should be dead, clients can still connect to it i.e.
the
> > > RemotingService.Connect call succeeds.
> > >
> > > What am I doing wrong? Thanks for any help :)
> > >
> > > Kind regards.
> > > --
> > > Tom Tempelaere.
> >
> >
> >


Ken Kolda

9/24/2004 3:14:00 PM

0

Yes, if the function is OneWay and the server disppears, the function calls
will not return an error (there is an exception: if the connection hasn't
been established yet then you will get an exception). You will need to use a
non-OneWay call if you wan to know for sure that the server is still alive.

Ken


"TT (Tom Tempelaere)" <_|\|_0$P@|/\|titi____AThotmailD.Tcom|/\|@P$0_|\|_>
wrote in message news:4D801D0F-FAB8-4B81-A107-6F059C027F6C@microsoft.com...
> Hey Ken,
>
> I noticed that the method I called does not throw any exception, even
though
> the log-app is not alive. Could that be due to the fact that my methods in
> the interface (IMyLog) are OneWay?
>
> Thanks,
> Tom T.
>
> "Ken Kolda" wrote:
>
> > The call to RemotingServices.Connect() does not actually cause a
connection
> > to be made to the server -- it just creates a proxy. The actual
connection
> > is made the first time you invoke a property or method on the proxy
object.
> > At that point you should get an exception indicating that no connection
can
> > be made to the server.
> >
> > Ken
> >
> >
> > "TT (Tom Tempelaere)"
<_|\|_0$P@|/\|titi____AThotmailD.Tcom|/\|@P$0_|\|_>
> > wrote in message
news:090D8A15-9C01-43A4-A4B1-958DDCDACB9C@microsoft.com...
> > > Hi there,
> > >
> > > In my current project I have a logging utility that is a standalone
app.
> > The
> > > utility shows log entries, other apps can connect to it and send
logging
> > > entries to be displayed.
> > >
> > > I use RemotingServices.Marshal at startup of the log util to allow
other
> > > apps to access the logging utility. When the log util is closed, I use
> > > RemotingServices.Disconnect to make the log app unavailable.
> > >
> > > The problem is that even when I close my log util, clients can still
> > connect
> > > to the remoted (log-)object. I'll add some code to clarify. Class
MyLog is
> > a
> > > MarshalByRefObject, which implements IMyLog which contains the real
> > > interface. MyLog overrides InitializeLifetimeService method and
returns
> > null
> > > as lease timeout.
> > >
> > > <code>
> > >
> > > // log-server startup:
> > > // ---------------------
> > > this.channel = new System.Runtime.Remoting.Channels.Tcp.TcpChannel (
> > > this.config.Channel
> > > );
> > >
> > > System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel (
> > > this.channel
> > > );
> > >
> > > this.myLog = new MyLog( this ); // the remoted object
> > >
> > > System.Runtime.Remoting.RemotingServices.Marshal (
> > > this.myLog,
> > > this.config.MyLogURI,
> > > typeof( IMyLog )
> > > );
> > >
> > > // log-server shutdown code:
> > > // ------------------------------
> > > if( this.myLog != null )
> > > System.Runtime.Remoting.RemotingServices.Disconnect (
> > > this.myLog
> > > );
> > >
> > > if( this.channel != null
> > > )System.Runtime.Remoting.Channels.ChannelServices.UnregisterChannel(
> > > this.channel );
> > >
> > > // client connection code:
> > > // --------------------------
> > > string connectionStr = "tcp://" + this.config.Address + ":" +
> > > this.config.Channel.ToString() +
"/" +
> > > this.config.MyLogURI;
> > >
> > > object objref = System.Runtime.Remoting.RemotingServices.Connect (
> > > typeof( IMyLog ),
> > > connectionStr
> > > );
> > >
> > > this.myLog = objref as IMyLog;
> > >
> > > </code>
> > >
> > > So, even if my log app is closed and hence the shutdown code is run
and
> > the
> > > remoted object should be dead, clients can still connect to it i.e.
the
> > > RemotingService.Connect call succeeds.
> > >
> > > What am I doing wrong? Thanks for any help :)
> > >
> > > Kind regards.
> > > --
> > > Tom Tempelaere.
> >
> >
> >