Library tutorials & articles
Introducing .NET Remoting
- Introduction
- Creating the shared library
- The server object
- The remote client
- Testing it out
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.
Related articles
Related discussion
-
Binary Studio | software development outsourcing Ukraine
by shane124 (4 replies)
-
Chart insertation in a windows form...
by pdhanik (1 replies)
-
Point of Sale Developers: Hardware & C# SDK
by ManiGovindan (7 replies)
-
help with the remote frame buffer protocol from real VNC
by poison (0 replies)
-
Need help making a complete program editable, C# or .net I think
by davelee (1 replies)
Related podcasts
-
A Practical Look at Silverlight 2 Part 1
Now that Silverlight 2 is at the Olympics and making a big splash, we wanted to explore this fascinating technology more. Microsoft Silverlight 2 is a cross-browser, cross-platform, and cross-device plug-in for delivering the next generation of .NET based media experiences and rich interactive ap...
Events coming up
-
Nov
18
15 Minutes of Fame
Dresher, United States
This is a yearly tradition. We select 10 of the favorite speakers from monthly meetings, code camps, and hands on labs. Each one does a 15 minute talk on their favorite .NET technology. This is our 10th anniversary so we plan a gala event with special prizes and refreshments.
forget that last post ...
I found it in my code ... non-application test code I threw in on the quick ... cause the StackOverflow.
Hey, did you ever find out what your problem was?
I got the same error on a completely different project.
Same M.O. ...
... unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll
during the first call to the object that was returned from the "Activator.GetObject()" call.
I encountered the following error message when running the ResumeClient.exe:
" An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll "
at the following line of code:
Resume resume = loader.GetResumeByUserID(1); ;
but I was able to observe the "New Reference Added!" string on the console of the ResumeSuperServer.
Could I safely assume that I already have "loader" as an object of "ResumeLoader", but I failed to obtain "resume" as an object of "Resume" ?
I was looking for a Remoting Sample for beginners for weeks and this was the first that made absolute sense to me. If you are a person with an average IQ like myself, and want to understand the basics of remoting implimentation, this is the tutorial for you!!
Thanks David for making learning Remoting easy and fun!!
I've been looking for a way to implement a cross application boundary component in C# .NET for most of this week. This looks like it will suit my needs perfectly. Thanks.
Thanks for pointing this out. I'll update the tutorial
change
ResumeLoader loader = (ResumeLoader)Activator.GetObject(
typeof(ResumeServer), "tcp://localhost:9932/ResumeLoader");
if(rs==null)
to
ResumeLoader loader = (ResumeLoader)Activator.GetObject(
typeof(ResumeLoader), "tcp://localhost:9932/ResumeLoader");
if(loader==null)
Note the typeof() change and the change of the test item.
Hope that is right (I would hate to have typos in my post fixing typos)
This thread is for discussions of Introducing .NET Remoting.