C#
  Home arrow C# arrow Page 4 - An Introduction To .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 
Sun Developer Network 
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? 
C#

An Introduction To .NET Remoting
By: David Talbot
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 8
    2002-08-28

    Table of Contents:
  • An Introduction To .NET Remoting
  • Creating The Shared Library
  • The Server Object
  • The Remote Client
  • 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


    An Introduction To .NET Remoting - The Remote Client


    (Page 4 of 5 )

    The ResumeClient object is the test user of our newly created ResumeSuperServer remote object. To start this project go to File->New->Project. Choose a Console Application as the application type and enter "ResumeClient" as the project's name. As in step 2, make sure you add a reference to our shared DLL created in step 1 and the System.Runtime.Remoting DLL.

    The code shown below has two lines of particular interest to .NET remoting. The first line creates a TCP client channel. This channel is not bound to a port. The second line actually gets a reference to our remote ResumeLoader object. The Activator.GetObject method returns a type of Object that we can then cast into our ResumeLoader.

    The parameters we pass in are extremely similar to what we passed to the RemotingConfiguration object for the server project. The first parameter is the type of the object. The second is the URI of our remote object:

    ChannelServices.RegisterChannel(new TcpClientChannel());
    ResumeLoader loader = (ResumeLoader)Activator.GetObject(
    typeof(ResumeLoader), "tcp://localhost:9932/ResumeLoader");


    The complete code for our ResumeClient is shown below:

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

    namespace ResumeClient
    {

    public class ResumeClient
    {

    public static void Main(string[] args)
    {
    ChannelServices.RegisterChannel(new TcpClientChannel());
    ResumeLoader loader = (ResumeLoader)Activator.GetObject(
    typeof(ResumeServer), "tcp://localhost:9932/ResumeLoader");

    if(loader==null)
    { Console.WriteLine("Unable to get remote referance"); }
    else
    {
    Resume resume = loader.GetResumeByUserID(1);
    Console.WriteLine("ResumeID:"+ resume.ResumeID);
    Console.WriteLine("UserID:"+ resume.UserID);
    Console.WriteLine("Title:"+ resume.Title);
    Console.WriteLine("Body:"+ resume.Body);
    }
    Console.ReadLine();//Keep the window from closing before we can read the result.
    }//END OF MAIN METHOD
    }//END OF ResumeClient Object
    }//END OF ResumeClientNamespace


    Compile this project and note the location of the executable.

    Testing It Out
    Create a table in your database with the following basic schema:

    Table Name-Resume
    ResumeID, numeric (autonumber)
    UserID, numeric
    Title, Char(30)
    Body, Text


    Double click on the server executable that we created in step 2 and then double click on the client executable that we created in step 3. If everything works out then you should see the row from the database that has a ResumeID of 1.

    More C# Articles
    More By David Talbot


     

    C# ARTICLES

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






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT