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

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
TABLE OF CONTENTS:
  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
SEARCH DEVARTICLES

Understanding .NET Remoting - Getting Started
(Page 2 of 8 )

To work with the examples and the sample applications used in this article, you will need the .NET Framework SDK Beta 1 bits. You should be able to compile and run all of the samples from the command-line, so it's not mandatory that you have Visual Studio.NET installed. Most of the samples we will be looking at will use ASP.NET client pages to consume the remoted objects. So you'll need to have IIS installed to run the samples. You can use the MakeAll.bat batch file in sample source code bundle provided with this article to build all the source files.

Let's actually get down to business and see how to actually expose a .NET object using remoting, so that it can accept service requests from remote clients. Now let's consider the options that are available to you to host the object remotely. You could host the object from:
  • Internet Information Server (IIS).
  • A managed .NET executable
  • COM+ Services. (Hosting your object from COM+ Services allows you to leverage all the rich features that COM+ provides such a Object pooling, Transaction Services, Just in Time Activation etc).

First let's take a look at the .NET object that we are going to remote. We will then host this object in Internet Information Server (IIS), so that it is available to remote clients. The example that we will take up is a fictitious Pizza Diner that publishes it's daily menu through a service deployed at a well known URI that customers can use to look up what's hot on the menu at their favorite pizza restaurant. Here's the code for the .NET object that we intend to remote:

namespace MyDiner
{
using System;
using System.Collections;

/// <summary>
/// PizzaDetails - Provides pizza details
/// Each element in the ArrayList is an object of type PizzaDetails
/// </summary>
[Serializable]
public class PizzaDetails {

public String m_strName;
public String m_strDescription;
public float m_fCost;

public String Name {
get {return m_strName;}
set {m_strName = value;}
}

public String Description {
get {return m_strDescription;}
set {m_strDescription = value;}
}

public float Cost {
get {return m_fCost;}
set {m_fCost = value;}
}

}//class PizzaDetails

/// <summary>
/// The Pizza Diner Remote Object
/// </summary>
public class Diner : MarshalByRefObject {

public Diner() {

System.Console.WriteLine("Constructor called");
listPizzaMenu = new ArrayList();
populatePizzaMenu();

}//Constructor

public ArrayList getPizzaMenu() {

System.Console.WriteLine("Received remote request from client");
return listPizzaMenu;

}//getPizzaMenu

private void populatePizzaMenu() {

PizzaDetails pizza1Obj = new PizzaDetails();
pizza1Obj.m_strName = "All Green - Weight watcher's delight";
pizza1Obj.m_strDescription = & _
"Green peppers, pineapple, olives and " & _
"lettuce with a low calorie cheese topping";
pizza1Obj.m_fCost = 8.50f;
listPizzaMenu.Add(pizza1Obj);
...

}//populatePizzaMenu

private ArrayList listPizzaMenu = null;

}//class

}//namespace


You can compile the above code from the command line using:

csc /out:MyDiner.dll /target:library Diner.cs

This produces the MyDiner.dll assembly for the remote object.

Now, the first thing that strikes you when you take a look at the code snippet above, is that the Diner class inherits from the MarshalByRefObject (MBR). All objects that you want to expose to clients at a well-known URN through .NET remoting need to derive from MarshalByRefObject . This will ensure that the client gets an appropriate Object Reference ( ObjRef ) back that it can use thereafter to construct a proxy for the remote object from the information that it ferreted out from the ObjRef . Under the hood, actually, there are 2 proxies created on the client, a TransparentProxy and a RealProxy . The RealProxy is the one that routes the call to the remote machine that hosts the object. Though you really don't have to be bothered about how the client interacts with the created proxies, it's nice to know what actually happens under the covers.


blog comments powered by Disqus
ASP.NET ARTICLES

- 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 
Support 

Developer Shed Affiliates

 




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