?
Solved

.net remoting c# example

Posted on 2006-06-19
2
Medium Priority
?
683 Views
Last Modified: 2008-01-09
Hi Experts,

I've been struggling with c# .net remoting examples but i'm not having much look.  i've tried this one un-successfully:

http://www.developer.com/net/cplus/article.php/1479761

Does anyone have any examples of ones that they know work 100%

Cheers
0
Comment
Question by:Oli999
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 3

Expert Comment

by:rinksno1
ID: 16932886
//Code for the remotable type
using System;

namespace Bhupinder.Remoting.MarshObject
{
    public class Greatings : MarshalByRefObject
    {
        public Greatings()
        {
            Console.WriteLine("Constructor called");

        }
        ~Greatings()
        {
            Console.WriteLine("Deconstructir called");
        }

        public void PrintText(string txt)
        {
            Console.WriteLine("Hey you need to print : {0}",txt);
        }
    }

}
//*************************
//Code for the Server
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;


namespace Bhupinder.Remoting.Server
{
    class ServerClass
    {
        static void Main(string[] args)
        {
            HttpChannel httpchn = new HttpChannel(8080);
            ChannelServices.RegisterChannel(httpchn,false);
            RemotingConfiguration.RegisterWellKnownServiceType
                (typeof(Bhupinder.Remoting.MarshObject.Greatings), "Greatings",
                WellKnownObjectMode.Singleton);
            Console.WriteLine("Press any key to end the server....");            
            Console.ReadLine();            

        }
    }
}
//*******************************************
//Code for the Client

using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;
using Bhupinder.Remoting.MarshObject;

namespace Bhupinder.Remoting.RemotingClient
{
    class Program
    {
        static void Main(string[] args)
        {
            HttpChannel httpchn = new HttpChannel();
            ChannelServices.RegisterChannel(httpchn, false);
            Greatings grt = (Greatings)Activator.GetObject(typeof(Greatings), "http://localhost:8080/Greatings");

            if (grt == null)
            {
                Console.WriteLine("Server down please try again after sometime");
                Console.ReadLine();
            }

            else
            {
                grt.PrintText("This will be printed...");
                Console.ReadLine();
            }

        }
    }
}


//***********************

The three sections above must be saved in three different files/projects..
A reference of System.Runtime.Remoting should be added to Server and the client.
This is a working version i have just checked before posting this...


rinks
0
 
LVL 3

Accepted Solution

by:
rinksno1 earned 1000 total points
ID: 16932889
And also The Remotable type reference should be added to the client and the server...
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question