tags:

views:

150

answers:

2

Hi.. i am studying .Net Remoting

i 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");
A: 

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.

adrianbanks
A: 

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.

Thorsten Dittmar
i solved this problem by creating interfacec. and by doing this client only have Reference to that interface not the complete implementation. which is more secure.
Mohsan