RemotingServices.IsObjectOutOfAppDomain什么时候会返回false?

时间:2009-06-11 10:24:00

标签: c# .net remoting

根据远程对象定义 - 调用者的应用程序域之外的任何对象都应被视为远程。

RemotingServices.IsObjectOutOfAppDomain - 如果远程对象位于同一个应用程序域中,则返回false。

在MSDN文章Microsoft .NET Remoting: A Technical Overview中 发现以下声明(在“代理对象”一节中) 方法调用远程对象:

  

...检查[方法]调用以确定它是否是有效方法   远程对象的远程对象以及远程对象的实例是否存在   与代理相同的应用程序域。如果这是真的,那很简单   方法调用被路由到实际对象。

当远程对象和代理将驻留在同一个应用程序域中时,我感到很惊讶。

示例示例:

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;
}
}
}

1 个答案:

答案 0 :(得分:0)

好吧,一个明显的情况是它返回false是指对象不是代理,但是本地域中的常规.NET对象(不涉及远程处理)。

我完全不了解MSDN说明; -p

相关问题