ARTICLE

.NET Remoting in a simple way

Posted by Rahul Kumar Saxena Articles | Visual Basic 2010 August 16, 2007
This article tells us what is remoting and how we can access remote object from one application to another application.
Download Files:
 
Reader Level:

Introduction:

 

Remoting is the process through which we can access any remote object from one application domain to another application domain.

 

For creating remote object the class object must be inherited by MarshalByRefObject class.


Application domain is the runtime environment of application, For MicrosoftWord, domain is MS office, for .NET program, .NET runtime environment.

 

Terms Used in Remoting:

  1. Proxy: To avoid conjunction in networking. Main work is task Distributing. There are two type of proxy.
  •  Transparent proxy (There is no physical existence , Created by IIS server)
  •  Real Proxy  (Physical Existence)
  1. Channel: Channel provides the medium for transfer data from one location to another location. There are two types of channel.
  • TCP(work with Predefined root Connection oriented) 
  • HTTP (No need predefined root) 

  1. Formatters: Change the data in an appropriate format that it can traverse through channels. There are two types of formatters: 
  • Binary
  • SOAP(Simple Object Access Protocol) 

  1. Sink: Sink is used for security point of view. Before sending the data, the Data will be encrypted. Some additional bit will be added with the data to secure the data. There are two types of sink
  • Envoy sink
  • Server Context Sink

Object Mode on Server: Two Types of Object Mode.

  • SingleCall
  • Singleton

For creating Remoting we have to create 3 applications:

 

  • class Library (Of which Remote Object will be created)
  • Server Application (Console Application)
  • Client Application (Window Application)

RemoteClass:

 

Imports System

Imports System.Collections.Generic

Imports System.Text

 

Namespace remoteclass

          Public Class xx

                   Inherits MarshalByRefObject

                   Public Function sum(ByVal a As Integer, ByVal b As Integer) As Integer

                              Return a + b

                   End Function

          End Class

End Namespace


Remote Server:

 

Imports System

Imports System.Collections.Generic

Imports System.Text

Imports System.Runtime.Remoting

Imports System.Runtime.Remoting.Channels

Imports System.Runtime.Remoting.Channels.Tcp

 

Namespace remoteserver

          Friend Class Program

                   Shared Sub Main(ByVal args As String())

                             Dim ch As TcpChannel = New TcpChannel(8085)

                             ChannelServices.RegisterChannel(ch)

                             RemotingConfiguration.RegisterWellKnownServiceType(GetType(remoteclass.xx),"rahul",WellKnownObjectMode.Singleton)

                             Console.Write("Sever is  Ready........")

                             Console.Read()

                   End Sub

          End Class

End Namespace

 

When user run this Remote Server application. 

 



Figure 1:  Server Application.


Remote Client:

 

Imports System

Imports System.Collections.Generic

Imports System.ComponentModel

Imports System.Data

Imports System.Drawing

Imports System.Text

Imports System.Windows.Forms

Imports System.Runtime.Remoting

Imports System.Runtime.Remoting.Channels

Imports System.Runtime.Remoting.Channels.Tcp

 

Namespace remoteclient

          Public Partial Class Form1

                   Inherits Form

                   'TcpChannel ch = new TcpChannel();

                   Private obj As remoteclass.xx = New remoteclass.xx()

             Public Sub New()

                      InitializeComponent()

             End Sub

 

                   Private Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)

                             'ChannelServices.RegisterChannel(ch);

                             obj = CType(Activator.GetObject(GetType(remoteclass.xx), "tcp://localhost:8085/rahul"), remoteclass.xx)

                             Dim x As Integer = Int32.Parse(textBox1.Text)

                             Dim y As Integer = Int32.Parse(textBox2.Text)

                             textBox3.Text = (obj.sum(x, y)).ToString()

                   End Sub

          End Class

End Namespace

 

When user run the application.


 

Figure 2: Client Application

 

NOTE: THIS ARTICLE IS CONVERTED FROM C# TO VB.NET USING A CONVERSION TOOL. ORIGINAL ARTICLE CAN BE FOUND ON C# Corner (http://www.c-sharpcorner.com/). 

Login to add your contents and source code to this article
share this article :
post comment
 

This is my first comment.... Thanks

Posted by raj p Jan 03, 2012

nice article.

Posted by Ehsan Alu Dec 07, 2010

Hi, I am working with vb.net remoting. Now before calling server's method I want to sense/listen whether server is available/responding or not so it will not throw me an error. Help me out. thank you

Posted by Divyesh Chapaneri Jan 04, 2008
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor