Remotable Type in VB.Net

In distributed applications, objects residing outside the application domain of the caller application are considered Remote Objects. These Remote Objects are required to derive from the MarshalByRefObject class, which serves as the base class for enabling remote communication.

MarshalByRefObject class

By deriving an object from the MarshalByRefObject class, it gains the necessary capabilities to be accessed remotely by other application domains. This class ensures that remote communication between the caller application and the Remote Object is handled correctly, enabling seamless interaction and data exchange.

Objects that do not inherit from the MarshalByRefObject class are referred to as Non-remotable Objects. These objects lack the necessary infrastructure to facilitate remote communication and are restricted to within the boundaries of a single application domain. They cannot be accessed or interacted with remotely by other application domains.

Therefore, to transform an object into a Remote Object, it is essential to derive it from the MarshalByRefObject class. This inheritance provides the object with the required functionality and guarantees that it can be accessed remotely by other application domains.

The following example creating a Remote Object in VB.Net, 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 return the current time from Remote Object.

Full Source VB.NET
Imports System Public Class RemoteTime Inherits MarshalByRefObject Private currentTime As String = "" Public Function getTime() As String currentTime = DateTime.Now.ToShortTimeString() Return "Remote Server Time : " & currentTime End Function End Class

Copy and paste the above VB.Net source code into a file and save it as RemoteTime.vb

Compile the class RemoteTime.vb into a library using the command-line tools that ship with the .NET Framework SDK.

At the command prompt in the directory in which you saved the file, type the following command:

vbc /t:library RemoteTime.vb

After you compile the RemoteTime.vb , you will get a file called RemoteTime.dll in the directory which you saved the source file.

Full Source VB.NET
Imports System Public Class RemoteTime Inherits MarshalByRefObject Private currentTime As String = "" Public Function getTime() As String currentTime = DateTime.Now.ToShortTimeString() Return "Remote Server Time : " & currentTime End Function End Class

By distinguishing between Remote Objects and Non-remotable Objects and understanding the implications of deriving from the MarshalByRefObject class, developers can design their application's object hierarchy to cater to remote communication requirements. This allows for efficient and secure access to objects residing outside the boundaries of the caller application's domain, enabling distributed application architectures and enhancing the scalability and flexibility of the system.

Conclusion

Objects residing outside the caller application's domain are categorized as Remote Objects and must derive from the MarshalByRefObject class to enable remote communication. In contrast, objects that do not inherit from MarshalByRefObject are considered Non-remotable Objects and are confined to the boundaries of a single application domain. Careful consideration of object inheritance and classification allows developers to design and implement distributed systems effectively, ensuring seamless communication and interaction between application domains.