简体   繁体   English

.NET远程处理中的困惑

[英]Confusion in .net Remoting

I am studying .net Remoting 我正在学习.net远程处理

I've read from MSDN, but in one step I am facing some confusion.. 我已经阅读了MSDN,但在第一步中,我面临一些困惑。

Three steps are required for remoting purpose. 远程处理需要三个步骤。

1 - RemoteObject 1- 远程对象

2 - Host 2- 主机

3 - Client 3- 客户

creating RemoteObject and Host is fine. 创建RemoteObject和Host很好。 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. 在这里,它使用新的运算符创建RemotableType对象。 Where as this Client application has reference of RemotableType.dll . 其中,此客户端应用程序具有RemotableType.dll引用。

When this dll is available locally then what is the purpose of calling SayHello() remotely? 如果该dll在本地可用,那么远程调用SayHello()的目的是什么?

I ran this client without running server and it still displays me Hello World message. 我在不运行服务器的情况下运行了此客户端,它仍显示我Hello World消息。

Is this creation of remoteObject with new operator is valid here? 使用new运算符创建的remoteObject在这里有效吗?

Where as the other method of getting remoteobject is: 另一种获取远程对象的方法是:

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

Calling new RemotableType() is simply creating a local instance of RemotableType on the client. 调用new RemotableType()只是在客户端上创建RemotableType的本地实例。 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. 使用Activator.GetObject()在客户端中为在主机应用程序中发布的RemotableType实例创建一个TransparentProxy。 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. 如果您的SayHello实现是返回入口程序集的名称(使用Assembly.GetEntryAssembly()),则即使您在客户端中运行,它也会返回Host.exe。

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. 通常,您将创建两个DLL:一个包含可远程对象的接口定义,另一个包含接口定义的实现。

You will then add the interface definition DLL to the client, while the server needs both DLLs. 然后,您将接口定义DLL添加到客户端,而服务器需要两个DLL。 The client will then create instances of the class using the Activator.GetObject(...) call. 然后,客户端将使用Activator.GetObject(...)调用创建该类的实例。

If you reference the implementation DLL from your client - as you pointed out - you do not have any advantages from the client/server implementation. 如您所指出的,如果您从客户端引用实现DLL,则从客户端/服务器实现中不会获得任何好处。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM