Blue Theme Orange Theme Green Theme Red Theme
 
Team Foundation Server Hosting
Home | Forums | Videos | Advertise | Certifications | Downloads | Blogs | Interviews | Jobs | Beginners | Training
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
Nevron Chart
Search :       Advanced Search »
Home » .NET Remoting » .NET Remoting in a simple way

.NET Remoting in a simple way

What is remoting? How we can access remote object from one application to another application?

Author Rank :
Page Views : 52964
Downloads : 1156
Rating :
 Rate it
Level : Beginner
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
Download Files:
Remoting.zip
 
 
DevExpress Free UI Controls
Become a Sponsor
Team Foundation Server Hosting
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 


Remoting is the process through which we can access any remote object from one application domain to another application domain.

 

For creating remote object the class object must be inherited by MarshalByRefObject class.


Application domain  is the runtime environment of application, For MicrosoftWord, domain is MS office, For .NET programme, .NET runtime environment.

 

Terms Used in Remoting

  • Proxy: To avoid conjunction in networking. Main work is task Distributing.There are two type of proxy.

    • Transparent proxy (There is no physical existence , Created by IIS server)
    • Real Proxy  (Physical Existence)
      
  • Channel: Channel provides the medium for transfer data from one location to another location. There  are two types of channel.

    • TCP(work with Predefined root Connection oriented) 
    • HTTP (No need predefined root) 
  1. Formatters: Change the data in an appropriate format that it can traverse through channels.

    There are two types of formatters
  •  Binary
  • SOAP(Simple Object Access Protocol) 
  1. Sink:  Sink is used for security point of view. Before sending the data, the Data will be encrypted. Some additional bit will be added with the data to secure the data. 

    There are two types of sink
  • Envoy sink
  • Server Context Sink

Object Mode On Server: Two Types of Object Mode .

  • SingleCall
  • Singleton

For creating Remoting we have to create 3 applications:

  • class Library (Of which Remote Object will be created)
  • Server Application (Console Application)
  • Client Application (Window Application)

RemoteClass

 

using System;

using System.Collections.Generic;

using System.Text;

 

namespace remoteclass

{

    public class xx:MarshalByRefObject

    {

        public int sum(int a, int b)

        {

             return a + b;

        }

    }

}

Remote Server

 

using System;

using System.Collections.Generic;

using System.Text;

using System.Runtime.Remoting;

using System.Runtime.Remoting.Channels;

using System.Runtime.Remoting.Channels.Tcp;

 

namespace remoteserver

{

    class Program

    {

        static void Main(string[] args)

        {

            TcpChannel ch=new TcpChannel(8085);

            ChannelServices.RegisterChannel(ch);

            RemotingConfiguration.RegisterWellKnownServiceType(typeof

                           (remoteclass.xx),"rahul",WellKnownObjectMode.Singleton);

            Console.Write("Sever is  Ready........");

            Console.Read(); 

        }

    }

} 

 

When user run this Remote Server application. 

 

Server.jpg

Figure 1:  Server Application.


Remote Client

 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Runtime.Remoting;

using System.Runtime.Remoting.Channels;

using System.Runtime.Remoting.Channels.Tcp;

 

namespace remoteclient

{

    public partial class Form1 : Form

    {

        //TcpChannel ch = new TcpChannel();

        remoteclass.xx obj = new remoteclass.xx();

       public Form1()

       {

           InitializeComponent();

       }

 

        private void button1_Click(object sender, System.EventArgs e)

        {

            //ChannelServices.RegisterChannel(ch);

            obj = (remoteclass.xx)Activator.GetObject(typeof(remoteclass.xx),

                           "tcp://localhost:8085/rahul");

            int x = Int32.Parse(textBox1.Text);

            int y = Int32.Parse(textBox2.Text);

            textBox3.Text = (obj.sum(x, y)).ToString();

        }       

    }

}

When user run the application.


ClientApplication.jpg

Figure 2: Client Application.

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
Login to add your contents and source code to this article
 [Top] Rate this article
 
 About the author
 
Rahul Kumar Saxena
Rahul shows great interests in working with Microsoft technologies. He specializes in the implementation of DataBase & Graphics. His area of expertise includes: C#, ASP.NET,ADO.NET,Windows Forms & Web Services. He hails from background , Master's in Computer Application. With programming he loves photography, traveling and reading books.
(Talabpur*)
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Discover the Top 5 .NET Memory Management Fundamentals
To write the best .NET code, you need to know exactly how the .NET framework really manages memory. Ricky Leeks presents the Top 5 fundamental facts of .NET memory management. Learn more.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
Team Foundation Server Hosting
Become a Sponsor
 Comments
Any configuration to system needed by Vijay On June 4, 2007
Hi, If I want ot run sample application in remoting, do i need to configure anything on system
Reply | Email | Modify 
Re: Any configuration to system needed by Praveen On June 5, 2007

Hi dear u have no need to configure any thing to your system to run this appliacation. Just do one thing after saving this sample application u mhave to debug the remoteclass application.

Reply | Email | Modify 
Client missing reference by Adam On June 4, 2007
I get this error when I run the client: Error 1 The type or namespace name 'remoteclass' could not be found (are you missing a using directive or an assembly reference?) I'm assuming there is some step to take in the references - a direct reference to the local class would defeat the purpose. What am i doing wrong?
Reply | Email | Modify 
Re: Client missing reference by Praveen On June 5, 2007

hi dear , do one thing after saving the application, debug the remoteclass application.

Reply | Email | Modify 
Accessing variables within the main form? by Adam On June 4, 2007
How can remoteclass access variables within the main form?
Reply | Email | Modify 
Re: Accessing variables within the main form? by William On October 24, 2008
use static variables in main programand you can access them from registred service type
Reply | Email | Modify 
Answers to my questions by Adam On June 5, 2007
Being new to remoting, i thought the answer to my questions might help some other people wondering the same things. To run this application you must reference remoteclass; however if you were doing an actual implementation of a client/server program you would create a "factory" of the class to ship with the client, and the actual implementation to ship with the server. The factory class, as I understand, is a basic outline that allows you to reference the object, but doesn't have the full coding so there is not a security risk of your object being deconstructed; it's only a reference capable outline. In regards to question about accessing variables in the main form, you can create a static method within the main form and reference it within remoteclass. You would have to be careful about multiple thread access though, a topic I'm still learning about. Hope this posts helps someone, good luck.
Reply | Email | Modify 
unable to get the required output by swarajya On July 8, 2007
"No connection could be made because the target machine actively refused it" this is the error i am getting in this area "textBox3.Text = (obj.sum(x, y)).ToString();". pls do the needful.
Reply | Email | Modify 
Re: unable to get the required output by Sean On August 2, 2007
Hi there, check for firewalls on the remote machine blocking the port you specified in the code (or the port you decided to use)
Reply | Email | Modify 
Re: Re: unable to get the required output by Brij On August 21, 2007

hi,

while using TCP u got to configure some group policies on server machine. if u run above code on a local machine this code will work(tough i 've nt checked it yet) but if use http channel instead of TCP channel u don't have to configure it will run straight away. 

Reply | Email | Modify 
thanks by mao On January 10, 2008
you type is well i can see it thanks wish communicate with you my msn: hjjlsjh@hotmail.com
Reply | Email | Modify 
Re: thanks by Rahul Kumar On February 14, 2008
THANKS
Reply | Email | Modify 
Explain why? by Hemanth On January 18, 2008
Even if i comment this line the code will work since you are directly referring the class library then tell me what is the use of remoting here. obj = (remoteclass.xx)Activator.GetObject(typeof(remoteclass.xx), "tcp://localhost:8085/rahul");
Reply | Email | Modify 
remote access by remote On February 11, 2008
Can i use this way to access another pc i mean from acomputer i can logon another computer access it remotely
Reply | Email | Modify 
Remoting Problem by Senthilkumar On March 13, 2008
I tried ur Remoting Application described in this article. I received the following error No connection could be made because the target machine actively refused it.. Can u give me the solution for this.
Reply | Email | Modify 
Re: Remoting Problem by Ameer On August 31, 2008
look.. i have run the client app on one machine and the server on other.. they both are connected to the same internet network.. but when i press sum.. an error occures : "No Connection could be made because the target machine actively refused it!.." that wt comes on the client! so what should i do.. to make it work and other thing.. if ur using the class called remoteclass .. why is that remoting.. when u have it added as a refference on the same project!? thank you
Reply | Email | Modify 
how! by Ameer On August 31, 2008
look.. i have run the client app on one machine and the server on other.. they both are connected to the same internet network.. but when i press sum.. an error occures : "No Connection could be made because the target machine actively refused it!.." that wt comes on the client! so what should i do.. to make it work and other thing.. if ur using the class called remoteclass .. why is that remoting.. when u have it added as a refference on the same project!? thank you
Reply | Email | Modify 
how! by Ameer On August 31, 2008
look.. i have run the client app on one machine and the server on other.. they both are connected to the same internet network.. but when i press sum.. an error occures : "No Connection could be made because the target machine actively refused it!.." that wt comes on the client! so what should i do.. to make it work and other thing.. if ur using the class called remoteclass .. why is that remoting.. when u have it added as a refference on the same project!? thank you
Reply | Email | Modify 
Re: how! by muscle On January 22, 2009
Did u check if your server machine firewall is blocking the tcp channel?you may get a prompt first time asking you to allow opening the port in the future.Also try starting the server before the client.
Reply | Email | Modify 
Thanks by George On February 20, 2009
Your code pointed me to the right direction for making some applications talk to each other over the network. As Hemanth mentioned that if he removed obj = (remoteclass.xx)Activator.GetObject(typeof(remoteclass.xx),"tcp://localhost:8085/rahul"); this will still work, which he is correct but with this line the same class is used from the server side. The way I have done it to test this is by creating a Class that does a Console.WriteLine instead of your sum. This way when the server is running and you enter a message in the textbox on the client side and click on the button, the message will be displayed on the server's console window. Now if you try and comment the above line you will get nothing since WinForm doesn’t support Console.WriteLine.
Reply | Email | Modify 
Good for beginners by Raunak On February 11, 2010
Good for beginners
Reply | Email | Modify 
Nice to have... by Sorin On April 29, 2010
Hello,

Thank you for the article, it was simple, good, and informative. It would be nice if in the future you would pay more attention to details, like including all the references needed for each project.

Paul
Reply | Email | Modify 
Port number in TCP by Dinesh On January 2, 2011
8085 is just a fictitious port number using TCP. The actual port number should be 6 to implement the Remoting concept in a proper way using 2 PC's based on Windows XP SP 2 operating system. Just Try it !
Reply | Email | Modify 
Discover the top 5 tips for understanding .NET Interop
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.