ASP.NET
  Home arrow ASP.NET arrow Page 5 - 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 - 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);
    ChannelServices.RegisterChannel(chan);

    // Register the object at a well known URI End point
    RemotingServices.RegisterWellKnownType ("MyDiner",
    "MyDiner.Diner",
    "MyDiner/Diner.soap",
    WellKnownObjectMode.Singleton);

    // 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.ReadLine();
    Console.WriteLine("Pizza Service going down. Please Wait .....");

    // Unregister the TCP Channel
    ChannelServices.UnregisterChannel(chan);

    }//Main

    }//class

    }//namespace


    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);
    ChannelServices.RegisterChannel(chan);

    // Create an instance of the remote object
    Diner dinerObj = (Diner)Activator.GetObject(typeof(Diner),
    "tcp://localhost:8080/MyDiner/Diner.soap");

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

    // Unregister the channel
    ChannelServices.UnregisterChannel(chan);

    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 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek