示例#1
0
        /// <summary>
        /// handles a request to the service server
        /// </summary>
        /// <param name="context">http context</param>
        protected override void HandleRequest(HttpListenerContext context)
        {
            string path = HttpExtensions.GetRelativePath(context.Request.Url.AbsoluteUri, Prefixes);

            if (!ignorelogginpaths.Contains(path))
            {
                OnRequestPath(path, context.Request?.RemoteEndPoint?.ToString());
            }

            if (ProcessRequest(context, path))
            {
                return;
            }

            if (context.Request.HttpMethod == "OPTIONS")
            {
                OnResponse(context, default(T));
            }
            else
            {
                IServiceHandler <T> handler = GetService(path);
                if (handler == null)
                {
                    throw new ServiceServerException($"Service handler for '{path}' not found");
                }

                T response;
                try {
                    response = handler.HandleRequest(context);
                }
                catch (Exception e) {
                    throw new ServiceServerException("Error handling request", e);
                }
                OnResponse(context, response);
            }
        }