Home arrow C# arrow Page 3 - 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 Server Object
(Page 3 of 5 )

There are actually several ways to create the server object. The most straightforward method is described below. In Visual Studio.NET, click on File->New Project. Choose a Command Line Application and name it ResumeSuperServer.

First things first. We need to add references to the required DLLs that will make this program work. Go to Project->Add Reference, and add a reference to the DLL that we created in step 1 by clicking the "Browse" button.

In order to use the .NET remoting functionality, you must add a reference to the DLL using Project->Add Reference. Under the .NET tab, choose the System.Runtime.Remoting.DLL and click OK.

Next you will need to add a reference to System.Runtime.Remoting.dll in the same way we did in step 1. The object is shown below and is fairly simple and straightforward. I'll explain each of the 3 lines of code that really matter to .NET remoting in the following paragraphs.

The TcpServerChannel is one of the two types of channels supported by .NET remoting. This will set up the port number we want our object to respond to requests on, and the ChannelServices.RegisterChannel will bind that port number to the TCP/IP stack on the operating system:

TcpServerChannel channel = new TcpServerChannel(9932);

The other type of channel that can be set up is HTTP, and is done simply by using the HttpServerChannel object in the System.Runtime.Remoting.Channels.Http namespace. The differances between using an HTTP and a TCP channel can be summed up simply -- If you're working with a local network connection then it's best to use TCP because of it's enhanced performance over using HTTP.

If you're working over the Internet then HTTP can sometimes be the only choice depending on firewall configurations. Keep in mind that if you do have control over the firewall, almost all firewalls can be configured to allow TCP traffic through on the port you've chosen to use for your object in addition to the DNAT you'll likely need to employ in most situations. If you don't know how to alter these rules, ask your system administrator.

"ResumeLoader", WellKnownObjectMode.SingleCall);

This line sets a few parameters on your service and binds the object you want to the name you want to use on this remote object. The first parameter is the object you're binding, typeof(ResumeLoader). The second parameter is the string that is the name for the object on the TCP or HTTP channel. For example, remote clients would refer to the above object as "tcp://localhost:9932/ResumeLoader".

The third parameter tells the container what should be done with the object when a request for the object comes in. WellKnownObjectMode.Single call makes a new instance of the object for each client while WellKnownObjectMode.Singleton uses one instance of the object for all callers.

The complete code for the object is shown below:

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

namespace ResumeServerServer
public class ResumeSuperServer
public static void Main(String[] args)
TcpServerChannel channel = new TcpServerChannel(9932);
"ResumeLoader", WellKnownObjectMode.SingleCall);
System.Console.WriteLine("Press Any Key");

Compile this program and note the location of the generated .EXE file.
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