Introducing .NET Remoting

The remote client

The ResumeClinet object is our 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 referance to our shared DLL created in step 1 and the System.Runtime.Remoting DLL.

The code 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 seond line actually gets a referance 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 on 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 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");

	if(loader==null)
	{ Console.WriteLine("Unable to get remote referance"); }
	else
	{
		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 MAIN METHOD
}//END OF ResumeClient Object
}//END OF ResumeClientNamespace

Compile this project and note the location of the executable.

You might also like...

Comments

About the author

David Talbot United States

David Talbot is an experienced Software Architect with a diverse background including creating network applicances, working with television set top boxes, building Billing/CRM systems, Web Port...

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“It works on my machine.” - Anonymous