SiteMap  | About    

C# Remotable Object

Any object outside the application domain of the caller application should be considered as Remote Object . A Remote Object that should be derived from MarshalByRefObject Class. Any object can be changed into a Remote Object by deriving it from MarshalByRefObject . Objects without inheriting from MarshalByRefObject are called Non-remotable Objects.

The following example creating a Remote Object in C#, RemoteTime , which send the current time to the Client Application using Remoting Framework. The RemoteTime class is derived from MarshalByRefObject and inside the class it has a method getTime() which returns the current time from the Remote Object.

using System; 

public class RemoteTime : MarshalByRefObject 
    private string currentTime = ""; 
    public string getTime() 
        currentTime = DateTime.Now.ToShortTimeString(); 
        return "Remote Server Time : " + currentTime; 

Copy and paste the above C# source code into a file and save it as RemoteTime.vb
Compile the class RemoteTime.cs into a library using the command-line tools that shiped with the Visual Studio SDK .

At the command prompt type the following command:

  csc /t:library RemoteTime.cs

After you compile the RemoteTime.cs , you will get a file called RemoteTime.dll in the directory where your compiler resides.

If your file RemoteTime.cs is residing in c:\src then you should type command like the following :

  csc /t:library c:\src\RemoteTime.cs (C) 2016    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.