Groups | Blog | Home
all groups > dotnet distributed apps > august 2005 >

dotnet distributed apps : TWO .NET REMOTING QUESTIONS



css
8/29/2005 3:17:02 PM
I have a server application which creates a remoting object as a singleton:

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

Question #1)
After RegisterWellKnownServiceType instantiates my RemoteObj, how can my
server app now access this object to call a function directly. Must it act
like any other client and call Activator.GetObject?

Question #2)

Where would I change the lease timings on this object?

Dan Jacques
8/31/2005 8:14:01 AM
I'm relatively new to remoting myself, but I believe I can answer your
questions:

[quoted text, click to view]

I originally did just that in my application. Dissatisfied, I performed
some research and ended up using the RemotingServices.Marshal static
function. On your remoting server application, the following code should
work:

RemotingObj remObj = new RemotingObj(args [you can put args in!]);
ObjRef ref = RemotingServices.Marshal(remObj, "URI",
typeof(RemotingInterface));

I was lead to believe from a dotnet247 posting that this resulted in
treatment equivalent to the RegisterWellKnownServiceType call with Singleton
behavior. From this point on, you have remObj, a reference to your remoted
object, on the server!

Here's the post on the subject:
http://www.dotnet247.com/247reference/msgs/35/179183.aspx

My own experiences seem to support this. Furthermore, you can use the 'ref'
ObjRef created from the Marhsl call to STOP remoting of that object
(something I haven't as of yet been able to successfully do with the
RegisterWellKnownServiceType command) using the RemotingServices.Unmarshal
and RemotingServices.Disconnect commands on the server.

[quoted text, click to view]

The MarshalByRefObject class from which all Well-known objects must derive
has an overrideable function called InitializeLifetimeService documented here
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemmarshalbyrefobjectclassinitializelifetimeservicetopic.asp

You just have to override this method in your remoted object and have it
css
8/31/2005 1:05:05 PM
Dan,

Thanks so much!!! marhal(0 was just what I needed.

I want to control lifetime at the server's discretion - not the object. So
I tried GetLifetime...() after Marshal() but that gave me a "null" value.


When is InitializeLifetime.. called? Because I was thinkng I might have
some properties/variables that could be set by the server when it created the
object prior to calling Marshal. Then, I could set those timing properties
(renew, etc....) so that the lifetime would be controlled by thiose server
set variables.


from the server
Could I do the folloingIts a litle frustrating that there isn't a way to
just get the object on the server

[quoted text, click to view]
AddThis Social Bookmark Button