.net Remoting 中的混乱

发布于 2024-07-23 22:36:57 字数 1192 浏览 2 评论 0 原文

我正在学习 .net 远程处理,

我已从 MSDN 中阅读,但在一步中我遇到了一些困惑。

远程处理需要三个步骤。

1 - RemoteObject

2 - 主机

3 - 客户端

创建RemoteObject和主机就可以了。 我了解所有事情,它使用配置文件进行主机和客户端配置。 在客户端中,它使用以下代码,

public static void Main(){
      RemotingConfiguration.Configure("Client.exe.config");
      RemotableType remoteObject = new RemotableType();
      Console.WriteLine(remoteObject.SayHello());
   }

这里它使用 new 运算符创建 RemotableType 的对象。 此客户端应用程序引用了 RemotableType.dll

当这个dll在本地可用时,远程调用SayHello()的目的是什么?

我在没有运行服务器的情况下运行了这个客户端,它仍然向我显示 Hello World 消息。

使用 new 运算符创建 RemoteObject 在这里有效吗?

获取远程对象的另一种方法是:

RObject remoteObject = (RObject)Activator.GetObject(typeof(RObject), "tcp://localhost:9999/RObject");

I am studying .net Remoting

I've read from MSDN, but in one step I am facing some confusion..

Three steps are required for remoting purpose.

1 - RemoteObject

2 - Host

3 - Client

creating RemoteObject and Host is fine. I understand all the things, it uses Configuration File for both Host and Client Configuration. In Client it uses the following code

public static void Main(){
      RemotingConfiguration.Configure("Client.exe.config");
      RemotableType remoteObject = new RemotableType();
      Console.WriteLine(remoteObject.SayHello());
   }

Here it is creating Object of RemotableType with new operator. Where as this Client application has reference of RemotableType.dll.

When this dll is available locally then what is the purpose of calling SayHello() remotely?

I ran this client without running server and it still displays me Hello World message.

Is this creation of remoteObject with new operator is valid here?

Where as the other method of getting remoteobject is:

RObject remoteObject = (RObject)Activator.GetObject(typeof(RObject), "tcp://localhost:9999/RObject");

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

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

发布评论

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

评论(2

爺獨霸怡葒院 2024-07-30 22:36:57

通常您将创建两个 DLL:一个包含远程对象的接口定义,另一个包含接口定义的实现。

然后,您将接口定义 DLL 添加到客户端,而服务器需要这两个 DLL。 然后,客户端将使用 Activator.GetObject(...) 调用创建该类的实例。

如果您从客户端引用实现 DLL - 正如您所指出的 - 您不会从客户端/服务器实现中获得任何优势。

Usually you will create two DLLs: One that contains an interface definitions for your remotable object and another one that contains the implementation of the interface definitions.

You will then add the interface definition DLL to the client, while the server needs both DLLs. The client will then create instances of the class using the Activator.GetObject(...) call.

If you reference the implementation DLL from your client - as you pointed out - you do not have any advantages from the client/server implementation.

临风闻羌笛 2024-07-30 22:36:57

调用 new RemotableType() 只是在客户端上创建 RemotableType 的本地实例。 调用它的任何方法都会在此实例上调用。

使用 Activator.GetObject() 在客户端中创建一个透明代理,指向在主机应用程序中发布的 RemotableType 实例。 对此调用任何方法都会对主机应用程序进行远程调用并在那里执行。 如果 SayHello 的实现是返回入口程序集的名称(使用 Assembly.GetEntryAssembly()),那么即使您在客户端中运行,它也会返回 Host.exe。

Calling new RemotableType() is simply creating a local instance of RemotableType on the client. Calling any methods on it will get called on this instance.

Using Activator.GetObject() is creating a TransparentProxy in the client to the instance of RemotableType that was published in the host application. Calling any methods on this will make a remote call to the host application and will execute there. If your implementaion of SayHello was to return the name of the entry assembly (using Assembly.GetEntryAssembly()), it would return Host.exe even though you are running in the client.

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