Home > Microsoft .Net Development Tips > C# Development > Remoting in .NET
Win Development Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

C# DEVELOPMENT

Remoting in .NET


Manish Mehta
11.22.2002
Rating: -4.00- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


Let other users know how useful this tip is by rating it below. Got a tip or code of your own you'd like to share? Submit it here!


.NET Remoting provides a way for application in different machines/domains to communicate with each other and offers a powerful yet easy way to communicate with objects in different app domains. Any object that executes outside the app domain can be considered as remote.

Remote objects are accessed via channels. Channels can be thought of as transport mechanism to pass messages to and from remote objects. All the method calls along with the parameters are passed to the remote object through the channel via HTTP or TCP.

I have also used the utility SOAPSUDS.EXE, which is used to generate proxies for the remote component. The following example will help you understand the remoting mechanism in .NET. I chose to use C# for this example. We will create a server that will have a method.

Step 1: Creating the server server.cs on machine1

using System;
using System.IO;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;
namespace Server 
{
   public class ServiceClass : MarshalByRefObject {
      public void AddMessage (String msg) 
  {
         Console.WriteLine (msg);
  }
}
public class ServerClass 
{
  public static void Main () 
  {
    HttpChannel c = new HttpChannel (1095);
    ChannelServices.RegisterChannel (c);
    RemotingConfiguration.RegisterWellKnownServiceType(typeof
    (ServiceClass),"ServiceClass",WellKnownObjectMode.Singleton);    
     Console.WriteLine ("Server ON at 1095");
     Console.WriteLine ("Press enter to stop the server...");
     Console.ReadLine ();
  }
 }
}

Save this file as Server.cs. Compile this file using:

csc /r:system.runtime.remoting.dll /r:system.dll Server.cs

This will generate a executable server.exe. Run this file. On the console you should see:

Server ON at 1095
Press enter to stop the server...

To check whether the HTTP channel is binded to the port, open the browser and type: http://localhost:1095/ServiceClass?WSDL.

You should see a XML file describing the service.

Step 2: Creating client proxy and code on machine2:

Creating a client proxy requires that you use a Microsoft tool called soapsuds.exe. This utility ready the XML description and generates a proxy assembly used to access the server. Go to a different machine and type in:

soapsuds -url:http://:1095/ServiceClass?WSDL -oa:Server.dll

This will create a proxy called Server.dll that will be used to access the remote object.

Client code TheClient.cs

>

using System; 
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;  
using System.Runtime.Remoting.Channels.Http;
using Server;
public class TheClient 
 {
    public static void Main (string[] args) 
  {
      HttpChannel c = new HttpChannel (1077);  
ChannelServices.RegisterChannel (c);
      ServiceClass sc = (ServiceClass) Activator.GetObject (typeof(ServiceClass),
      "http://:1095/ServiceClass"); 
      sc.AddMessage ("Hello From Client"); 
  }
 }

Save this file as TheClient.cs. Compile it using:

csc /r:system.runtime.remoting.dll /r:system.dll /r:Server.dll TheClient.cs

The output will be TheClient.exe. Run it and check the server console on machine 1. You will see "Hello From Client."

This example used HTTP Channel to transport messages to remote components. Likewise TCP channel can also be used to achieve the same result. More information regarding .NET remoting can be found at http://msdn.microsoft.com/library/techart/hawkremoting.htm


Source: DotNetExtreme.com

Rate this Tip
To rate tips, you must be a member of SearchWinDevelopment.com.
Register now to start rating these tips. Log in if you are already a member.




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
C# Development
Let Microsoft StyleCop tame your wild C#
Picking a .NET smart client communications technology
LINQ beyond queries: Strong-typed refection
Book excerpt: An introduction to DSL tools
Assembly versioning in the .NET Framework 2.0
Book excerpt: Creating graphical output using the .NET Compact Framework
On Extension Methods in C# and .NET Framework 3.5
Generate RSA public and private keys, export to XML
Book excerpt: Upgrading to Visual Studio 2005
Learning .NET: Tips for getting started with .NET development

Web services and SOA implementations in the .NET Framework
Goin' mobile with Windows
Microsoft "WebSphere Loves Windows" ads tout cost, performance vs. AIX
Microsoft releases new CTP of Oslo SDK
Microsoft's Oslo modeling platform, the M language and .NET
Outgoing Bill Gates says UML on tap in Oslo SOA modeler
Podcast: Windows CardSpace authors speak
Open XML SDK ready for the road
Some of the Zen of Volta
Scaling WCF applications can challenge development teams
Security interoperability with .NET/WSE and WebLogic Workshop 8.1

C# programming language
Inside Visual Studio 2010
Mono 2.0 moves .NET apps to Linux - includes migration analyzer
LINQ beyond queries: Strong-typed refection
Assembly versioning in the .NET Framework 2.0
Book excerpt: Creating graphical output using the .NET Compact Framework
Visual Studio 2008 Learning Guide: C# 3.0
Simonyi firm to address divide between domain experts and developers
On Extension Methods in C# and .NET Framework 3.5
Generate RSA public and private keys, export to XML
Book excerpt: Upgrading to Visual Studio 2005

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
scripting language  (SearchWinDevelopment.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



Database Programming Solutions - .NET XML, Visual Studio LINQ, ORM .NET
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2000 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts