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

发布于 2024-07-24 06:41:14 字数 1695 浏览 3 评论 0原文

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

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

在 MSDN 文章 Microsoft .NET Remoting:技术概述我 发现以下声明(在“代理对象”段落中)关于 远程对象上的方法调用:

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

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

示例:

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

As per Remote Object definition- Any object outside the application domain of the caller should be considered remote.

RemotingServices.IsObjectOutOfAppDomain- returns false if remote object resides in the same app domain.

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.

So I am surprised when the remote object and proxy will reside in the same app domain.

sample example:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

樱花细雨 2024-07-31 06:41:14

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

我也不完全理解 MSDN 说明;-p

Well, one obvious case when it will return false is when the object isn't a proxy, but is a regular .NET object in the local domain (no remoting involved).

I don't understand the MSDN note fully, either ;-p

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文