.NET Remoting in VB.NET

This article tells us what is remoting and how we can access remote object from one application to another application.
  • 2207
 

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. 

 

Image1.jpg

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.


  Image2.jpg

Figure 2: Client Application

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.