ASP.NET
  Home arrow ASP.NET arrow Page 2 - Understanding .NET Remoting
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP.NET

Understanding .NET Remoting
By: Wrox Team
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 64
    2002-11-25

    Table of Contents:
  • Understanding .NET Remoting
  • Getting Started
  • Hosting the Remote Object on IIS
  • Method 1 (contd.)
  • Hosting the Remote Object in a Managed .NET Application Executable
  • Transport Channels
  • Serialization Formatters
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    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.

    More ASP.NET Articles
    More By Wrox Team


       · Very good article. Congratulations It is old but helped me a lot. In my case my...
     

    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







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    Stay green...Green IT