I'll try to answer your first question.
IsObjectOutOfAppDomain's implementation is (a little Reflector[1]-powered
reverse engineering:)
public static bool IsObjectOutOfAppDomain(object tp)
{
return RemotingServices.IsClientProxy(tp);
}
IsClientProxy is internal method, which looks like this:
internal static bool IsClientProxy(object obj)
{
MarshalByRefObject obj1;
bool flag1;
bool flag2;
Identity identity1;
obj1 = (obj as MarshalByRefObject);
if (obj1 == null)
{
return false;
}
flag1 = false;
identity1 = MarshalByRefObject.GetIdentity(obj1, &(flag2));
if ((identity1 != null) && ((identity1 as ServerIdentity) == null))
{
flag1 = true;
}
return flag1;
}
GetIdentity (please bear with me) has the following implementation:
internal static Identity GetIdentity(MarshalByRefObject obj, [out] ref bool
fServer)
{ Identity identity1;
fServer = 1;
identity1 = null;
if (obj != null)
{
if (!RemotingServices.IsTransparentProxy(obj))
{
identity1 = ((Identity) obj.__identity);
}
else
{ fServer = 0;
identity1 = RemotingServices.GetRealProxy(obj).IdentityObject;
}
}
return identity1;
}
Your object is MarshalByRefObject, and IsTransparentProxy returns true, its
__identity is indeed initialized (I inspected it with the quickwatch
window), so GetIdentity returns a non-null instance.
Back to IsClientProxy. It checks whether the identity of your object IS NOT
a ServerIdentity, and indeed it is not, so the MS implementation looks fine
and IsObjectOutOfAppDomain should return TRUE, although you don't expect
that. Now the only thing which I cannot check is the implementation of
IsTransparentProxy method, so... I'm done.
HTH,
Stoyan Damov
[1] http://www.aisto.com/roeder/dotnet/
-----Original Message-----
From: Moderated discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] Behalf Of Martin Bischoff
Sent: 08/14/2003 11:10
To: [EMAIL PROTECTED]
Subject: [ADVANCED-DOTNET] Remoting: "remote" object in same AppDomain
as the client
Hi,
I already posted this to microsoft.public.dotnet.framework, but would be
interested, if anyone here can tell me something about it:
In the MSDN article "Microsoft .NET Remoting: A Technical Overview" I
found the following statement (in the paragraph "Proxy Objects") about
method calls on remote objects:
"...the [method] call is examined to determine if it is a valid method
of the remote object and if an instance of the remote object resides in
the same application domain as the proxy. If this is true, a simple
method call is routed to the actual object."
I have created a simple remoting application which is server and client
at the same time (see below). In the sample, I instantiate the remote
object and then want to check whether it resides in the same AppDomain
as the client code.
To do so I call RemotingServices.IsObjectOutOfAppDomain(obj). I would
have expected this method to return false because client and "remote"
object are in the same AppDomain, but it returns true.
Another thing i found out is the following:
After running some rudimentary performance comparisions (using a
somewhat more complex sample), it seems to me that calling the remote
object's method takes roughly the same time no matter whether the remote
object exists in the same AppDomain or when it really is instantiated in
a different AppDomain/process (on the same machine). E.g.:
calling the remote object's method 20000 times takes:
- not measurable when called on a local instance
- 13 seconds when used as shown in the sample below
- 15 seconds when the object really is remote (different AppDomain, same
machine though)
So here are my questions:
1/ Is there a bug in RemotingServices.IsObjectOutOfAppDomain(obj)?
Shouldn't this method return false, when the "remote" object resides in
the same AppDomain as the client (as described above)?
2/ When the remote object resides in the same AppDomain as the client,
is there any optimization done by the framework (e.g. bypassing the
network stack)? My rudimentary tests made me think that there's no such
optimization, even though something like this is mentioned in the MSDN
articled cited above (at least that's how I understood the statement)
Thanks for your input,
Martin Bischoff
here's the example (example.cs):
----------------------------------
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
namespace RemotingSamples
{
public class HelloServer : MarshalByRefObject
{
public HelloServer()
{
Console.WriteLine("HelloServer activated");
}
public String HelloMethod(String name)
{
return "Hi there " + name;
}
}
public class Server
{
public static int Main(string [] args)
{
// server code
ChannelServices.RegisterChannel(new TcpChannel(8085));
RemotingConfiguration.RegisterWellKnownServiceType(
typeof(HelloServer), "SayHelloSingleton",
WellKnownObjectMode.Singleton);
// client code
HelloServer obj = HelloServer)Activator.GetObject(
typeof(HelloServer), "tcp://localhost:8085/SayHelloSingleton");
System.Console.WriteLine(
"IsTransparentProxy={0}, IsOutOfAppDomain={1}",
RemotingServices.IsTransparentProxy(obj),
RemotingServices.IsObjectOutOfAppDomain(obj));
Console.WriteLine(obj.HelloMethod("server"));
return 0;
}
}
}
----------------------------------
===================================
This list is hosted by DevelopMentor. http://www.develop.com
NEW! ASP.NET courses you may be interested in:
2 Days of ASP.NET, 29 Sept 2003, in Redmond
http://www.develop.com/courses/2daspdotnet
Guerrilla ASP.NET, 13 Oct 2003, in Boston
http://www.develop.com/courses/gaspdotnet
View archives and manage your subscription(s) at http://discuss.develop.com
===================================
This list is hosted by DevelopMentor� http://www.develop.com
NEW! ASP.NET courses you may be interested in:
2 Days of ASP.NET, 29 Sept 2003, in Redmond
http://www.develop.com/courses/2daspdotnet
Guerrilla ASP.NET, 13 Oct 2003, in Boston
http://www.develop.com/courses/gaspdotnet
View archives and manage your subscription(s) at http://discuss.develop.com