Solved

.net remoting c# example

Posted on 2006-06-19
2
659 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 250 total points
ID: 16932889
And also The Remotable type reference should be added to the client and the server...
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

733 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