Exemple #1
0
        private static void StartService()
        {
            ServiceHost host = new ServiceHost();

            host.AddService(new HelloWorldService());

            host.StartServiceHost();
            host.OpenServices();

            Console.WriteLine("Press enter to stop server");
            Console.ReadLine();

            host.CloseServices();
            host.StopServiceHost();
        }
        public void TestQueue()
        {
            ServiceHost host = new ServiceHost();

            InvokeQueueTestService testService = new InvokeQueueTestService();

            host.AddService(testService);

            host.StartServiceHost();
            host.OpenServices();

            using (ManualResetEvent callbackEvent = new ManualResetEvent(false))
            {
                object state = new object();

                IAsyncResult resultFromCallback;
                object stateFromCallback;
                bool callbackWorked = false;

                IInvokeQueueTestInterface testInterface = testService.GetTestInterface(null);

                /*
                Hmm, blocking from deferreds is a bit tricky.

                Deferred<int> result = testInterface.GetReactorThreadId(false);

                int reactorThreadId = testService.EndGetReactorThreadId(result);

                Assert.AreNotEqual(Thread.CurrentThread.ManagedThreadId, reactorThreadId);
                Assert.AreNotEqual(0, reactorThreadId);
                */

                bool callbackCompleted = callbackEvent.WaitOne(2000, false);

                Assert.IsTrue(callbackCompleted);
                Assert.IsTrue(callbackWorked);
            }

            host.StopServiceHost();
        }
Exemple #3
0
        private static void StartChatRoomServer(ChatroomSettings settings)
        {
            ServiceHost host = new ServiceHost();

            host.AddService(new ChatroomService(settings));

            host.StartServiceHost();
            host.OpenServices();

            Console.WriteLine("Type \"quit\" to shut down server");

            string input = null;

            do
            {
                input = Console.ReadLine();
                Console.WriteLine(input);
                //TODO: Implement Console Commands
            }
            while (input != "quit");

            host.CloseServices();
            host.StopServiceHost();
        }