示例#1
0
        protected void Start(IEnumerable <string> urlBases, WaitCallback listenCallback)
        {
            // *** Already running - just leave it in place
            if (this.IsStarted)
            {
                return;
            }

            if (this.Listener == null)
            {
                Listener = CreateHttpListener();
            }

            foreach (var urlBase in urlBases)
            {
                if (HostContext.Config.HandlerFactoryPath == null)
                {
                    HostContext.Config.HandlerFactoryPath = ListenerRequest.GetHandlerPathIfAny(urlBase);
                }

                Listener.Prefixes.Add(urlBase);
            }

            try
            {
                Listener.Start();
                IsStarted = true;
            }
            catch (HttpListenerException ex)
            {
                if (Config.AllowAclUrlReservation && ex.ErrorCode == 5 && registeredReservedUrl == null)
                {
                    foreach (var urlBase in urlBases)
                    {
                        registeredReservedUrl = AddUrlReservationToAcl(urlBase);
                        if (registeredReservedUrl == null)
                        {
                            break;
                        }
                    }

                    if (registeredReservedUrl != null)
                    {
                        Listener = null;
                        Start(urlBases, listenCallback);
                        return;
                    }
                }

                throw ex;
            }

            ThreadPool.QueueUserWorkItem(listenCallback);
        }
示例#2
0
        /// <summary>
        /// Starts the Web Service
        /// </summary>
        /// <param name="listeningAtUrlBase">
        /// A Uri that acts as the base that the server is listening on.
        /// Format should be: http://127.0.0.1:8080/ or http://127.0.0.1:8080/somevirtual/
        /// Note: the trailing slash is required! For more info see the
        /// HttpListener.Prefixes property on MSDN.
        /// </param>
        protected void Start(string listeningAtUrlBase, WaitCallback listenCallback)
        {
            // *** Already running - just leave it in place
            if (this.IsStarted)
            {
                return;
            }

            if (this.Listener == null)
            {
                Listener = new System.Net.HttpListener();
            }

            HostContext.Config.HandlerFactoryPath = ListenerRequest.GetHandlerPathIfAny(listeningAtUrlBase);

            Listener.Prefixes.Add(listeningAtUrlBase);

            IsStarted = true;

            try
            {
                Listener.Start();
            }
            catch (HttpListenerException ex)
            {
                if (Config.AllowAclUrlReservation && ex.ErrorCode == 5 && registeredReservedUrl == null)
                {
                    registeredReservedUrl = AddUrlReservationToAcl(listeningAtUrlBase);
                    if (registeredReservedUrl != null)
                    {
                        Start(listeningAtUrlBase, listenCallback);
                        return;
                    }
                }

                throw ex;
            }

            ThreadPool.QueueUserWorkItem(listenCallback);
        }