Beispiel #1
0
        internal static string GetClientProxyScript(HttpContext context)
        {
            WebServiceData webServiceData   = WebServiceData.GetWebServiceData(context, context.Request.FilePath);
            DateTime       lastModifiedDate = GetAssemblyModifiedTime(webServiceData.TypeData.Type.Assembly);

            // If the browser sent this header, we can check if we need to resend
            string modifiedSince = context.Request.Headers["If-Modified-Since"];

            if (modifiedSince != null)
            {
                DateTime header;
                if (DateTime.TryParse(modifiedSince, out header))
                {
                    // We are done if the assembly hasn't been modified
                    if (header >= lastModifiedDate)
                    {
                        context.Response.StatusCode = 304;
                        return(null);
                    }
                }
            }
            bool debug = RestHandlerFactory.IsClientProxyDebugRequest(context.Request.PathInfo);

            // Only cache for release proxy script (/js)
            if (!debug)
            {
                // Only cache if we get a reasonable last modified date
                if (lastModifiedDate.ToUniversalTime() < DateTime.UtcNow)
                {
                    // Cache the resource so we don't keep processing the same requests
                    HttpCachePolicy cachePolicy = context.Response.Cache;
                    cachePolicy.SetCacheability(HttpCacheability.Public);
                    cachePolicy.SetLastModified(lastModifiedDate);
                    // expires is necessary so that the browser at least does an If-Modified-Since request on every request.
                    // without that, the browser wouldn't request a new proxy until the user hits refresh.
                    // Use one year ago to reasonably ensure "past" interpretation
                    cachePolicy.SetExpires(lastModifiedDate.AddYears(-1));
                }
            }

            WebServiceClientProxyGenerator proxyGenerator = new WebServiceClientProxyGenerator(context.Request.FilePath, debug);

            return(proxyGenerator.GetClientProxyScript(webServiceData));
        }
Beispiel #2
0
        public virtual IHttpHandler GetHandler(HttpContext context, string requestType, string url, string pathTranslated)
        {
            IHttpHandler        handler;
            IHttpHandlerFactory factory;

            if (RestHandlerFactory.IsRestRequest(context))
            {
                // It's a REST request
                factory = _restHandlerFactory;
            }
            else
            {
                // It's a regular asmx web request, so delegate to the WebServiceHandlerFactory
                factory = _webServiceHandlerFactory;
            }

            handler = factory.GetHandler(context, requestType, url, pathTranslated);

            bool requiresSession = handler is IRequiresSessionState;

            if (handler is IHttpAsyncHandler)
            {
                if (requiresSession)
                {
                    return(new AsyncHandlerWrapperWithSession(handler, factory));
                }
                else
                {
                    return(new AsyncHandlerWrapper(handler, factory));
                }
            }

            if (requiresSession)
            {
                return(new HandlerWrapperWithSession(handler, factory));
            }
            else
            {
                return(new HandlerWrapper(handler, factory));
            }
        }