Solved

.net remoting c# example

Posted on 2006-06-19
2
629 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
  • 2
2 Comments
 
LVL 3

Expert Comment

by:rinksno1
Comment Utility
//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
Comment Utility
And also The Remotable type reference should be added to the client and the server...
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now