Beispiel #1
0
        private static void StartServer(Type interfaceType, Type implType, string pipeName)
        {
            //create the server
            var controller = new RpcController();
            
            var server = new RpcServer(controller);

            //register the service with the server. We must specify the interface explicitly since we did not use attributes
            server.GetType()
                  .GetMethod("RegisterService")
                  .MakeGenericMethod(interfaceType)
                  .Invoke(server, new[] {Activator.CreateInstance(implType)});

            //build the connection using named pipes
            try
            {
                pipeServerStreamIn = CreateNamedPipe(pipeName + "ctos", PipeDirection.In);
                pipeServerStreamOut = CreateNamedPipe(pipeName + "stoc", PipeDirection.Out);
                streamsCreated = true;
                pipeServerStreamIn.WaitForConnection();
                pipeServerStreamOut.WaitForConnection();
                
                //create and start the channel which will receive requests
                var channel = new StreamRpcChannel(controller, pipeServerStreamIn, pipeServerStreamOut, useSharedMemory: true);
                channel.Start();
            }
            catch (IOException e)
            {
                //swallow and exit
                Console.WriteLine("Something went wrong (pipes busy?), quitting: " + e);
                throw;
            }
        }
Beispiel #2
0
        private static void StartServer(Type interfaceType, Type implType, string pipeName)
        {
            //create the server
            var controller = new RpcController();

            var server = new RpcServer(controller);

            //register the service with the server. We must specify the interface explicitly since we did not use attributes
            server.GetType()
            .GetMethod("RegisterService")
            .MakeGenericMethod(interfaceType)
            .Invoke(server, new[] { Activator.CreateInstance(implType) });

            //build the connection using named pipes
            try
            {
                pipeServerStreamIn  = CreateNamedPipe(pipeName + "ctos", PipeDirection.In);
                pipeServerStreamOut = CreateNamedPipe(pipeName + "stoc", PipeDirection.Out);
                streamsCreated      = true;
                pipeServerStreamIn.WaitForConnection();
                pipeServerStreamOut.WaitForConnection();

                //create and start the channel which will receive requests
                var channel = new StreamRpcChannel(controller, pipeServerStreamIn, pipeServerStreamOut, useSharedMemory: true);
                channel.Start();
            }
            catch (IOException e)
            {
                //swallow and exit
                Console.WriteLine("Something went wrong (pipes busy?), quitting: " + e);
                throw;
            }
        }