Advertisement

02.04.2004 at 09:06AM PST, ID: 20873286
[x]
Attachment Details

.NET Remoting

Asked by DarrenD in C# Programming Language

Tags: remoting, tcpclientchannel

Hi there,

I am trying to create a remote object which uses Interfaces and .Net Remoting

I am really wondering if I am on the right track or if I need to go and review everything that I am doing. Any help or updates in code would be greatly appriciated.

What I want to do is listed in four steps so my question is this:

Is what I want to do possible??

1: Create an Interface DLL with a namespace  DoSomethingInterface which contains a Class IDoSomething which has a method GetString that returns a string.

Code:
using System;
namespace DoSomethingInterface
{
      public interface IDoSomething
      {
        string GetString() ;
      }
}


2: Create a seperate DLL with a namespace DoSomethingImplementation which contains a class DoSomethingImplementation which implements IDoSomething.

Code:
using System ;
using System.Runtime.Remoting ;
using System.Runtime.Serialization ;
using DoSomethingInterface ;
namespace DoSomethingImplementation
{
      [Serializable]
      public class DoSomethingImp : MarshalByRefObject, IDoSomething
      {
            public DoSomethingImp()
            {
            }

            string IDoSomething.GetString()
            {
                  return "This is a string from DoSomethingImp" ;
            }

      }
}

4: Create a Console/Service application called DoSomethingServer which listens for Remoting Tcp requests for the IDoSomething class.
Code:
using System;
using System.Runtime.Remoting ;
using System.Runtime.Remoting.Channels ;
using System.Runtime.Remoting.Channels.Tcp ;
using System.Runtime.Serialization ;
using DoSomethingInterface ;
namespace DoSomethingServer
{
      class EnrtyPoint
      {
            [STAThread]
            static void Main(string[] args)
            {
                  TcpServerChannel myChannel = new TcpServerChannel(9988) ;
                  ChannelServices.RegisterChannel(myChannel) ;

                  RemotingConfiguration.RegisterWellKnownServiceType(typeof                    (IDoSomething),"IDoSomething",WellKnownObjectMode.SingleCall) ;

                  Console.WriteLine("Server Running") ;
                  Console.WriteLine("Press Any Key!") ;
                  Console.ReadLine() ;
            }
      }
}

5: Create a Client Console application which calls the DoSomethingImplementation via the DoSomethingServer and the IDoSomethingInterface
Code:
using System;
using System.Runtime.Remoting ;
using System.Runtime.Remoting.Channels ;
using System.Runtime.Remoting.Channels.Tcp ;
using DoSomethingInterface ;
namespace DoSomethingClient
{
      class Client
      {
            [STAThread]
            static void Main(string[] args)
            {
      ChannelServices.RegisterChannel(new TcpClientChannel()) ;
                  IDoSomething myDoSomething = (IDoSomething)Activator.GetObject(typeof(IDoSomething),"tcp://localhost:9988/DoSomethingImp") ;
                  Console.WriteLine(myDoSomething.GetString().ToString()) ;
                  Console.WriteLine("Press Any Key!") ;
                  Console.ReadLine() ;
            }
      }
}

Thanks for any help in advanceStart Free Trial
[+][-]02.04.2004 at 10:16PM PST, ID: 10278234

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: C# Programming Language
Tags: remoting, tcpclientchannel
Sign Up Now!
Solution Provided By: mogun
Participating Experts: 1
Solution Grade: A
 
 
[+][-]02.05.2004 at 02:09AM PST, ID: 10279169

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.05.2004 at 02:29AM PST, ID: 10279275

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.05.2004 at 02:59AM PST, ID: 10279418

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32