예제 #1
0
        /// <summary>
        /// 通过实现 System.Web.IHttpHandler 接口的自定义 HttpHandler 启用 HTTP Web 请求的处理。
        /// </summary>
        /// <param name="context">它提供对用于为 HTTP 请求提供服务的内部服务器对象(如 Request、Response、Session和 Server)的引用。</param>
        public void ProcessRequest(HttpContext context)
        {
            WebRequestDecoder webRequestDecoder = WebRequestDecoder.CreateInstance(context);

            if (webRequestDecoder == null)
            {
                webRequestDecoder = new SimpleUrlDecoder(context);
            }
            string logicalMethod = webRequestDecoder.LogicalMethod;
            ResponseAnnotationAttribute methodAnnotation   = this.GetMethodAnnotation(logicalMethod);
            WebResponseEncoder          webResponseEncoder = WebResponseEncoder.CreateInstance(context, methodAnnotation.ResponseFormat);

            if (webResponseEncoder == null)
            {
                webResponseEncoder = new JQueryScriptEncoder(context);
            }
            try
            {
                this.Pre_Invoke(context);
                object srcObj = this.InvokeMethod(logicalMethod, webRequestDecoder.Deserialize());
                webResponseEncoder.Write(srcObj);
            }
            catch (Exception ex)
            {
                string message = (ex.InnerException == null) ? ex.Message : ex.InnerException.Message;
                this.ResponseException(context, message, webResponseEncoder);
            }
            WebAjaxHandler.InitializeCachePolicy(context, methodAnnotation);
        }
예제 #2
0
        /// <summary>
        /// 创建解码器
        /// </summary>
        /// <param name="context">当前上下文</param>
        /// <returns>解码器</returns>
        public static WebRequestDecoder CreateInstance(HttpContext context)
        {
            WebRequestDecoder result = null;
            string            text   = context.Request.ContentType.ToLower();

            if (text.IndexOf("application/json") >= 0)
            {
                result = new JsonDecoder(context);
            }
            else if (text.IndexOf("application/x-www-form-urlencoded") >= 0)
            {
                result = new SimpleUrlDecoder(context);
            }
            return(result);
        }