コード例 #1
0
        private void ListenerCallback(IAsyncResult ar)
        {
            HttpListenerCallbackState callbackState = (HttpListenerCallbackState)ar.AsyncState;
            HttpListenerContext       context       = null;

            //
            try
            {
                context = callbackState.Listener.EndGetContext(ar);
            }
            catch (Exception ex)
            {
                Console.WriteLine("WebServiceGateway: " + ex.Message + "\n" + ex.StackTrace);
            }
            finally
            {
                callbackState.ListenForNextRequest.Set();
            }
            if (context == null)
            {
                return;
            }
            //
            Worker(context);
        }
コード例 #2
0
 private void ListenAsynchronously(IEnumerable<string> prefixes)
 {
     HttpListener listener = new HttpListener();
     foreach (string s in prefixes)
     {
         listener.Prefixes.Add(s);
     }
     listener.Start();
     HttpListenerCallbackState state = new HttpListenerCallbackState(listener);
     ThreadPool.QueueUserWorkItem(Listen, state);
 }
コード例 #3
0
        private void StartListener(IEnumerable <string> prefixes)
        {
            stopEvent.Reset();
            HttpListener listener = new HttpListener();

            foreach (string s in prefixes)
            {
                listener.Prefixes.Add(s);
            }
            listener.Start();
            HttpListenerCallbackState state = new HttpListenerCallbackState(listener);

            ThreadPool.QueueUserWorkItem(Listen, state);
        }
コード例 #4
0
 private void Listen(object state)
 {
     HttpListenerCallbackState callbackState = (HttpListenerCallbackState)state;
     while (callbackState.Listener.IsListening)
     {
         callbackState.Listener.BeginGetContext(new AsyncCallback(ListenerCallback), callbackState);
         int n = WaitHandle.WaitAny(new WaitHandle[] { callbackState.ListenForNextRequest, stopEvent });
         if (n == 1)
         {
             // stopEvent was signalled 
             callbackState.Listener.Stop();
             break;
         }
     }
 }
コード例 #5
0
        private void StartListener(IEnumerable <string> prefixes)
        {
            stopEvent.Reset();
            HttpListener listener = new HttpListener();

            if (servicePassword != "")
            {
                listener.AuthenticationSchemes = AuthenticationSchemes.Basic;
            }
            foreach (string s in prefixes)
            {
                listener.Prefixes.Add(s);
            }
            listener.Start();
            HttpListenerCallbackState state = new HttpListenerCallbackState(listener);

            ThreadPool.QueueUserWorkItem(Listen, state);
        }
コード例 #6
0
        private void Listen(object state)
        {
            HttpListenerCallbackState callbackState = (HttpListenerCallbackState)state;

            while (callbackState.Listener.IsListening)
            {
                callbackState.Listener.BeginGetContext(new AsyncCallback(ListenerCallback), callbackState);
                int n = WaitHandle.WaitAny(new WaitHandle[] { callbackState.ListenForNextRequest, stopEvent });
                if (n == 1)
                {
                    // stopEvent was signaled
                    try
                    {
                        callbackState.Listener.Stop();
                    }
                    catch (Exception e)
                    {
                        MigService.Log.Error(e);
                    }
                    break;
                }
            }
        }
コード例 #7
0
        private void ListenerCallback(IAsyncResult result)
        {
            HttpListenerCallbackState callbackState = (HttpListenerCallbackState)result.AsyncState;
            HttpListenerContext       context       = null;

            callbackState.ListenForNextRequest.Set();
            try
            {
                context = callbackState.Listener.EndGetContext(result);
            }
            catch (Exception ex)
            {
                MigService.Log.Error(ex);
            }
            //finally
            //{
            //    callbackState.ListenForNextRequest.Set();
            //}
            if (context == null)
            {
                return;
            }
            Worker(context);
        }
コード例 #8
0
 private void ListenAsynchronously(IEnumerable<string> prefixes)
 {
     HttpListener listener = new HttpListener();
     foreach (string s in prefixes)
     {
         listener.Prefixes.Add(s);
     }
     listener.Start();
     HttpListenerCallbackState state = new HttpListenerCallbackState(listener);
     ThreadPool.QueueUserWorkItem(Listen, state);
 }
コード例 #9
0
 private void StartListener(IEnumerable<string> prefixes)
 {
     stopEvent.Reset();
     HttpListener listener = new HttpListener();
     foreach (string s in prefixes)
     {
         listener.Prefixes.Add(s);
     }
     listener.Start();
     HttpListenerCallbackState state = new HttpListenerCallbackState(listener);
     ThreadPool.QueueUserWorkItem(Listen, state);
 }
コード例 #10
0
 private void StartListener(IEnumerable<string> prefixes)
 {
     stopEvent.Reset();
     HttpListener listener = new HttpListener();
     if (servicePassword != "")
     {
         listener.AuthenticationSchemes = AuthenticationSchemes.Basic;
     }
     foreach (string s in prefixes)
     {
         listener.Prefixes.Add(s);
     }
     listener.Start();
     HttpListenerCallbackState state = new HttpListenerCallbackState(listener);
     ThreadPool.QueueUserWorkItem(Listen, state);
 }