Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 698
  • Last Modified:

.net remoting c# example

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
Oli999
Asked:
Oli999
  • 2
1 Solution
 
rinksno1Commented:
//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
 
rinksno1Commented:
And also The Remotable type reference should be added to the client and the server...
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now