Home arrow C# arrow Page 4 - An Introduction To .NET Remoting

An Introduction To .NET Remoting

.Net remoting lets us work with remote objects programatically. In this article David gives us the 101 on .NET remoting and shows us how to create a remote object.

Author Info:
By: David Talbot
Rating: 4 stars4 stars4 stars4 stars4 stars / 12
August 28, 2002
  1. · An Introduction To .NET Remoting
  2. · Creating The Shared Library
  3. · The Server Object
  4. · The Remote Client
  5. · Conclusion

print this article

An Introduction To .NET Remoting - The Remote Client
(Page 4 of 5 )

The ResumeClient object is the test user of our newly created ResumeSuperServer remote object. To start this project go to File->New->Project. Choose a Console Application as the application type and enter "ResumeClient" as the project's name. As in step 2, make sure you add a reference to our shared DLL created in step 1 and the System.Runtime.Remoting DLL.

The code shown below has two lines of particular interest to .NET remoting. The first line creates a TCP client channel. This channel is not bound to a port. The second line actually gets a reference to our remote ResumeLoader object. The Activator.GetObject method returns a type of Object that we can then cast into our ResumeLoader.

The parameters we pass in are extremely similar to what we passed to the RemotingConfiguration object for the server project. The first parameter is the type of the object. The second is the URI of our remote object:

ChannelServices.RegisterChannel(new TcpClientChannel());
ResumeLoader loader = (ResumeLoader)Activator.GetObject(
typeof(ResumeLoader), "tcp://localhost:9932/ResumeLoader");

The complete code for our ResumeClient is shown below:

using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using DotNetRemoteTest;

namespace ResumeClient

public class ResumeClient

public static void Main(string[] args)
ChannelServices.RegisterChannel(new TcpClientChannel());
ResumeLoader loader = (ResumeLoader)Activator.GetObject(
typeof(ResumeServer), "tcp://localhost:9932/ResumeLoader");

{ Console.WriteLine("Unable to get remote referance"); }
Resume resume = loader.GetResumeByUserID(1);
Console.WriteLine("ResumeID:"+ resume.ResumeID);
Console.WriteLine("UserID:"+ resume.UserID);
Console.WriteLine("Title:"+ resume.Title);
Console.WriteLine("Body:"+ resume.Body);
Console.ReadLine();//Keep the window from closing before we can read the result.
}//END OF ResumeClient Object
}//END OF ResumeClientNamespace

Compile this project and note the location of the executable.

Testing It Out
Create a table in your database with the following basic schema:

Table Name-Resume
ResumeID, numeric (autonumber)
UserID, numeric
Title, Char(30)
Body, Text

Double click on the server executable that we created in step 2 and then double click on the client executable that we created in step 3. If everything works out then you should see the row from the database that has a ResumeID of 1.
blog comments powered by Disqus

- Introduction to Objects and Classes in C#, P...
- Visual C#.NET, Part 1: Introduction to Progr...
- C# - An Introduction
- Hotmail Exposed: Access Hotmail using C#
- Razor Sharp C#
- Introduction to Objects and Classes in C#
- Making Your Code CLS Compliant
- Programming with MySQL and .NET Technologies
- Socket Programming in C# - Part II
- Socket Programming in C# - Part I
- Creational Patterns in C#
- Type Conversions
- Creating Custom Delegates and Events in C#
- Inheritance and Polymorphism
- Understanding Properties in C#

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials