Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
SQL Server

How - To Remoting - Client Server Using VB.Net (Part Two)

Author: DevASP
Download Source Code :

This article shows that How The Host project contains a Windows Forms application that will read an XML configuration file to make available the classes defined in the RemoteCustomer project.

In order for the client to 'load' the objects, it reads Host.exe.config file at startup. The application's assumption is that the file lives in the same directory as the exe file.  Note that the file itself is stored at the source directory level as app.config. When you compile the application, the file is automatically copied to the output directory with the correct name.

This Article is designed to show how to use the .NET Remoting architecture using three types of remote objects. In addition, it uses XML configuration files to specify available objects and server location information instead of hard-coding them into the binaries or putting the data into the system registry.

Featured Highlights

The Source Code contains three solutions:

  • VB.NET How-To Remoting - Server
  • VB.NET How-To Remoting - Host
  • VB.NET How-To Remoting - Client

Each solution has one project.

One of the projects (RemoteCustomer) is a class library that exposes three creatable types:

  • Customer (client activated)
  • SingleCallCustomer (WellKnown singlecall)
  • SingletonCustomer (WellKnown singleton)

To make it easier to configure, each class lives in the same namespace, RemotingSample, which is defined in each class source file.

The Host project contains a Windows Forms application that will read an XML configuration file named Host.exe.config to make available the classes defined in the RemoteCustomer project. For a production application, you might want to host the class library (RemoteCustomer.dll) in a Windows service. <System.Diagnostics.DebuggerStepThrough()> has been added to some procedures since they are not the focus of the demo. Remove them if you wish to debug the procedures. This code simply shows the About form.


#Region " Standard Menu Code "

<System.Diagnostics.DebuggerStepThrough()> Private Sub mnuAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuAbout.Click

End Sub

' This code will close the form.

<System.Diagnostics.DebuggerStepThrough()> Private Sub mnuExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuExit.Click

' Close the current form


End Sub

End Region


This function iterates through all the ClientActivatedService types that were loaded via the remotingConfiguration.Configure (Remoting.config) file.


Private Sub ListClientActivatedServiceTypes()

     Dim entry As ActivatedServiceTypeEntry

For Each entry In RemotingConfiguration.GetRegisteredActivatedServiceTypes()

Me.lstOutput.Items.Add("Registered ActivatedServiceType: " & entry.TypeName)


End Sub


This function iterates through all the WellKnownService types that were loaded via the RemotingConfiguration.Configure (Remoting.config) file.

Private Sub ListWellKnownServiceTypes()

           Dim entry As WellKnownServiceTypeEntry

           For Each entry In RemotingConfiguration.GetRegisteredWellKnownServiceTypes()

                Me.lstOutput.Items.Add(entry.TypeName & " is available at " & entry.ObjectUri)


End Sub

In Forms Load Event Read in Host.exe.config file The call to RemotingConfiguration.Configure loads in the xml configuration file and lets the remoting architecture know what types to make available via remoting.

After loading the remoting.config file enumerate the list of ClientActivated types and WellKnown types and list them in the list box on the form.


Private Sub frmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load


     Me.lstOutput.Items.Add("Loading Activated Configuration File")




           Catch exp As Exception

                Dim txt As String

                txt = "I was unable to load the file remoting.config or it is not in the correct format." & vbCrLf & _

                 "Please make sure it is located in the same directory as this exe " & _

                 " and that it is in the correct format." & vbCrLf & _"Please see the Help, About box for the location of this exe." & vbCrLf & vbCrLf & _"Detailed Error Information below:" & vbCrLf & vbCrLf & _"  Message: " & exp.Message & vbCrLf & _"  Source: " & exp.Source & vbCrLf & vbCrLf & _"  Stack Trace:" & vbCrLf & _



MessageBox.Show(txt, "Generic Exception", MessageBoxButtons.OK, MessageBoxIcon.Stop)


Me.lstOutput.Items.Add("Unabled to load objects.")

End Try

End Sub

Instructions for Running the Sample

Before running the demo, you need to build all three projects. You should build them in this order:

  1. RemoteCustomer
  2. Host
  3. Client

Once the binaries have been build, you will need to start the Host application first to make sure your objects are available for remoting. Next start your client.

If you wish to test on two different machines, you will need to make changes to the client's .config file changing localhost to an IP address or DNS name for the server machine. In addition, you might need to change the server's file if you change the port number. See the comments in both the client's .config file and the host's .config file for examples.

I Explain Some of Important functions here Source code is given with that article. Comments are very Important With Code.this is the Part Two of  How To TCP Remoting Using VB.Net

Article Comments
this is good article about remoting

Posted on 12/21/2006 4:44:18 PM by vinit

hi this is good. and can you help me for my project.
i want to open the C: drive of server using its hostname in vb.for this i want help

Posted on 10/29/2008 8:23:04 AM by Mohan

Hi,this is good.plz help me for my prj. i.e Employee Communication Management in .Help me for Configuration of server & Client

Posted on 1/28/2010 2:18:40 AM by Priyanka shisode

This is good, and i need how to sent a request to Lan server from client , Please help me.

Posted on 6/24/2010 5:50:06 AM by Thangaraj Erode

Add Article Comment:
Name :
Email Address :
Comments :
<< How- To Remoting – Client Server Using VB.Net (Part 1)

Disclaimer - Privacy
© 2002-2017