Home arrow ASP.NET arrow Page 5 - Understanding .NET Remoting

Understanding .NET Remoting

In this article, Aravind shows you how to build scalable, reliable and high-performance web services using the .NET remoting infrastructure.

Author Info:
By: Wrox Team
Rating: 4 stars4 stars4 stars4 stars4 stars / 108
November 25, 2002
  1. · Understanding .NET Remoting
  2. · Getting Started
  3. · Hosting the Remote Object on IIS
  4. · Method 1 (contd.)
  5. · Hosting the Remote Object in a Managed .NET Application Executable
  6. · Transport Channels
  7. · Serialization Formatters
  8. · Conclusion

print this article

Understanding .NET Remoting - Hosting the Remote Object in a Managed .NET Application Executable
(Page 5 of 8 )

In the last section, we hosted the remote .NET object in IIS and then used an ASP.NET page to invoke the object. Now, let's see how we can host the same object in a managed .NET application executable. Take a look at this snippet of code that shows you how your managed application host should register a channel and expose the remote object at a well known remote URN endpoint.

namespace MyDinerHost
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels.TCP;

class DinerHost
public static void Main(String[] args) {

// Create and register the TCPChannel
// Let's listen at port 8080
TCPChannel chan = new TCPChannel(8080);

// Register the object at a well known URI End point
RemotingServices.RegisterWellKnownType ("MyDiner",

// Ready to listen for requests.
// Up and running until the user presses a key
Console.WriteLine("John Doe's Pizza Menu Query Host is up and running");
Console.WriteLine("Press any key to shut me down .....");
Console.WriteLine("Pizza Service going down. Please Wait .....");

// Unregister the TCP Channel




You will also need to place the MyDiner.dll assembly in the same directory as the host application or register it with the global assembly cache so that the host application can locate the assembly that contains the Diner object.

You can compile the source from command line using:

csc /out:MyDinerHost.exe /target:exe /r:System.Runtime.Remoting.dll,MyDiner.dll DinerManagedHost.cs

This time we will try using a TCP channel for our remote invocation. You will notice how the Main entry point in the application registers a TCP Channel, so that it can listen for incoming requests on a specified port. In the earlier IIS hosting example, IIS took care of listening for HTTP requests.

Now, since we are hosting the object in our very own hosting application, we need to register the channel and then listen for requests on that channel. In the code snippet that we just saw, the ChannelServices.RegisterChannel method call registers a TCP channel and listens on port 8080 for requests. Then, we expose the remote object at a well-known URN endpoint using RemotingServices.RegisterWellKnownType.

The last parameter in RegisterWellKnownType defines the actual activation policy. In this example, we use the Singleton activation policy that uses the same object instance to service every client request. We will take a more detailed look at the various activation policies in the Lifetime management and Activation policies section. So if you use the earlier ASP.NET client to access the service hosted in your .NET executable, you would just need to register a TCP channel in the client instead of a HTTP Channel.

The code snippet below shows how to register a TCP Channel and then activate and invoke a method on the remote object:

// Create and register a tcp channel
TCPChannel chan = new TCPChannel(8081);

// Create an instance of the remote object
Diner dinerObj = (Diner)Activator.GetObject(typeof(Diner),

// Get Todays Menu from the remote Pizza Service
if(dinerObj != null) m_listPizza = dinerObj.getPizzaMenu();

// Unregister the channel

blog comments powered by Disqus

- How Caching Means More Ca-ching, Part 2
- How Caching Means More Ca-ching, Part 1
- Reading a Delimited File Using ASP.Net and V...
- What is .Net and Where is ASP.NET?
- An Object Driven Interface with .Net
- Create Your Own Guestbook In ASP.NET
- HTTP File Download Without User Interaction ...
- Dynamically Using Methods in ASP.NET
- Changing the Page Size Interactively in a Da...
- XML Serialization in ASP.NET
- Using Objects in ASP.NET: Part 1/2
- IE Web Controls in VB.NET
- Class Frameworks in VB .NET
- Cryptographic Objects in C#: Part 1
- Sample Chapter: Pure ASP.Net

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-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials