Interview questions

Remote object

<<Previous   Next>>

.Net Remoting - remote object - Dec 29, 2009 at 15:33 PM by Nishant Kumar 

Create a remote object

To create remote class, you need to inherit from MarshalByRefObject class.

Imports System.Runtime.Remoting
Public Class MyRemoteObj Inherits MarshalByRefObject
        Public Function Welcome(ByVal Name as String)
            Console.WriteLine("This is my first remoting object") 
            return "Welcome " + name
        End Function
End Class

In the above code, we have created a class that inherits from MarshalByRefObject. Now we create a host application that hosts the remote object. This host application will read detail of remote object from configuration file and wait for the client to connect to it.

Imports System
Imports System.Runtime.Remoting

Public class Test
          Public Shared Sub Main()
                  RemotingConfiguration.Configure("MyApp.exe.config")
                  Console.WriteLine("Press return to Exit")
                  Console.ReadLine()
          End Sub
End Class

Here, the application read the configuration file using RemotingConfiguration.Configure method.

Here is code for configuration file, MyApp.exe.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
      <system.runtime.remoting>
           <application>
               <service>
                   <wellknown mode="SingleCall" 
                      type="MyRemoteObj,MyRemoteObj"
                      objectUri="MyRemoteObject">
                   </wellknown>
               </service>
               <channels>
                      <channel ref="tcp server" port="8080"/> 
               </channels>
          </application>
     </system.runtime.remoting>
</configuration>

In the configuration file, we have exposed remote object using TCP channel.

Once the hosting application is started, then client applications can start creating instances of the remote object and invoke its methods.

Important points for .Net Remoting

.Net Remoting produce good performance in terms of speed when use with TCP channel and the binary formatter.
.Net remoting when hosted in IIS, can benefit from all the security features of IIS. If you use TCP or HTTP channel hosted in processes other than aspnet_wp.exe, you need to implement security features on your own.
.NET Remoting supports state management with Singleton objects.   

<<Previous   Next>>
 



Write your comment - Share Knowledge and Experience


 

 
Latest placement tests
Latest links
 
Latest MCQs
» General awareness - Banking » ASP.NET » PL/SQL » Mechanical Engineering
» IAS Prelims GS » Java » Programming Language » Electrical Engineering
» English » C++ » Software Engineering » Electronic Engineering
» Quantitative Aptitude » Oracle » English » Finance
Home | About us | Sitemap | Contact us | We are hiring