C# Remotable Object

In case of a caller application, any object residing outside its application domain should be regarded as a Remote Object. For an object to be classified as a Remote Object, it must derive from the MarshalByRefObject Class. By deriving from MarshalByRefObject, any regular object can be transformed into a Remote Object. Conversely, objects that do not inherit from MarshalByRefObject are referred to as Non-remotable Objects. It is crucial to distinguish between these two types of objects to effectively manage and interact with them within the application architecture.

MarshalByRefObject

The following example demonstrates the creation of a Remote Object called RemoteTime in C#. This RemoteTime object utilizes the Remoting Framework to send the current time to a Client Application. The RemoteTime class is derived from MarshalByRefObject, indicating its remote accessibility. Within the class, there is a method named getTime() that retrieves and returns the current time from the Remote Object. This implementation showcases how the Remoting Framework enables communication between the RemoteTime object and the Client Application, facilitating the exchange of time-related information.

Full Source C#
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

Conclusion

C# Remotable Objects are objects that can be accessed and interacted with remotely across application domains or even across different machines, enabling distributed communication and functionality.