none
.NET Remoting design question

    Întrebare

  • Hi

    I have a server application which needs a simple console program to issue commands to the server. I am completely new to .NET Remoting but I thought this could be the right way to establish communication between console and server.

    So I have defined a Marshal object in a shared DLL.

    But... How can I implement server side logic without having to put all server logic in the shared DLL? So far I have made following design:

        public class ClientRequestHandler : MarshalByRefObject, IClientRequestHandler
        {
            private static IClientRequestHandler serverClientRequestHandler;
    
            public static void InitializeServerClientRequestHandler(IClientRequestHandler clientRequestHandler)
            {
                serverClientRequestHandler = clientRequestHandler;
            }
    
            public bool Start(string serviceName)
            {
                if(serverClientRequestHandler == null)
                {
                    throw new Exception("ServerClientRequestHandler not assigned");
                }
                return serverClientRequestHandler.Start(serviceName);
            }
    
            public bool Stop(string serviceName)
            {
                if (serverClientRequestHandler == null)
                {
                    throw new Exception("ServerClientRequestHandler not assigned");
                }
                return serverClientRequestHandler.Stop(serviceName);
            }
    
            public string[] ShowStatus()
            {
                return new[] {"THIS", "IS", "TESTING"};
            }
        }
    

    The idea is that

    IClientRequestHandler

    is an interface that defines the command being processed on the server and thus, the marshall objects implement it as well. Since I have no influence on object creation, my thought was to initialize the static 

    serverClientRequestHandler

    in the following manner:

                TcpChannel tcpChannel = new TcpChannel(remotingPort);
                ChannelServices.RegisterChannel(tcpChannel); 
                ClientRequestHandler.InitializeServerClientRequestHandler(new MyServerClientRequestHandler(....));
                RemotingConfiguration.RegisterWellKnownServiceType(Type.GetType("ProcessRunnerCommons.ClientRequestHandler,object"), remotingName, WellKnownObjectMode.Singleton);
    

    It doesnt strike me as a good way - but it is the only way I can think of.

    So I hoped for some input from you guys.

    TIA

    /Søren



    Best regards Soeren D.

    12 martie 2012 15:54

Răspunsuri

Toate mesajele