Remote Server C#

Associate
Joined
7 Oct 2005
Posts
609
Remote Object

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ServerClass
{
    public class myRemoteClass : MarshalByRefObject
    {
        public myRemoteClass()
        {
        }

        public bool SetString(String sTemp)
        {
            try{
                Console.WriteLine("This String '{0}' has a length of {1}", sTemp, sTemp.Length);
                return sTemp != "";
            }
            catch
            {
                return false;
            }
        }
    }
}

Server
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

namespace RemoteServer
{
    class RemoteServer
    {
        static void Main(string[] args)
        {
            TcpChannel chan = new TcpChannel(5354);
            ChannelServices.RegisterChannel(chan);

            RemotingConfiguration.RegisterWellKnownServiceType(
                System.Type.GetType("ServerClass.myRemoteClass, ServerClass"),
                "RemoteTest",
                WellKnownObjectMode.SingleCall);

            System.Console.WriteLine("Hit <enter> to exit...");
            System.Console.ReadLine();

        }
    }
}

Client
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using ServerClass;

namespace RemoteClient
{
    class RemoteClient
    {
        static void Main(string[] args)
        {
            TcpChannel chan = new TcpChannel();
            ChannelServices.RegisterChannel(chan);

            myRemoteClass obj = (myRemoteClass)Activator.GetObject(typeof(myRemoteClass),
            "tcp://localhost:5354/RemoteTest");
            if (obj == null)
                System.Console.WriteLine("Could not locate server");
            else
                if (obj.SetString("Sending String to Server"))
                    System.Console.WriteLine("Success: Check the other console to verify.");
                else
                    System.Console.WriteLine("Sending the test string has failed.");

            System.Console.WriteLine("Hit <enter> to exit...");
            System.Console.ReadLine();


        }
    }
}

I am trying to create a simple remote client/server program. The example above is off a microsoft site i copied. Everything complies ok and i have created the server and client exe's and also the remoteobject.dll. I have also referenced the dll in the client and server.

When I try run my server it keeps crashing. I get a windows error saying that remote server has encountered a problem send error report/ dont send. I followed all he instructions on the microsoft site and cant seem to find whats wrong with it.

There are two folders in each project obj and bin and they both contain exe for the server and for the client, I tried running both but they keep crashing also.

Anybody any ideas on where I'm going wrong?
 
Back
Top Bottom