示例#1
0
        /// <summary>
        /// Retrieves instance of the page from Spring web application context.
        /// </summary>
        /// <param name="context">current HttpContext</param>
        /// <param name="requestType">type of HTTP request (GET, POST, etc.)</param>
        /// <param name="url">requested page URL</param>
        /// <param name="path">translated server path for the page</param>
        /// <returns>instance of the configured page object</returns>
        IHttpHandler IHttpHandlerFactory.GetHandler(HttpContext context, string requestType, string url, string path)
        {
            new AspNetHostingPermission(AspNetHostingPermissionLevel.Minimal).Demand();

            IConfigurableApplicationContext appContext =
                WebApplicationContext.GetContext(url) as IConfigurableApplicationContext;

            if (appContext == null)
            {
                throw new InvalidOperationException(
                          "Implementations of IApplicationContext must also implement IConfigurableApplicationContext");
            }

            string appRelativeVirtualPath = WebUtils.GetAppRelativePath(url);

            AbstractHandlerFactory.NamedObjectDefinition nod =
                AbstractHandlerFactory.FindWebObjectDefinition(appRelativeVirtualPath, appContext.ObjectFactory);

            Type serviceType = null;

            if (nod != null)
            {
#if !MONO
                if (appContext.IsTypeMatch(nod.Name, typeof(WebServiceExporter)))
                {
                    WebServiceExporter wse = (WebServiceExporter)appContext.GetObject(nod.Name);
                    serviceType = wse.GetExportedType();
                }
                else
                {
                    serviceType = appContext.GetType(nod.Name);
                    // check if the type defines a Web Service
                    object[] wsAttribute = serviceType.GetCustomAttributes(typeof(WebServiceAttribute), true);
                    if (wsAttribute.Length == 0)
                    {
                        serviceType = null;
                    }
                }
#else
                serviceType = appContext.GetType(nod.Name);

                // check if the type defines a Web Service
                object[] wsAttribute = serviceType.GetCustomAttributes(typeof(WebServiceAttribute), true);
                if (wsAttribute.Length == 0)
                {
                    serviceType = null;
                }
#endif
            }

            if (serviceType == null)
            {
                serviceType = WebServiceParser.GetCompiledType(url, context);
            }


#if !MONO_2_0
            return((IHttpHandler)CoreGetHandler.Invoke(this, new object[] { serviceType, context, context.Request, context.Response }));
#else
            // find if the BuildManager already contains a cached value of the service type
            var buildCacheField = typeof(BuildManager).GetField("buildCache", BindingFlags.Static | BindingFlags.NonPublic);
            var buildCache      = (IDictionary)buildCacheField.GetValue(null);

            if (!buildCache.Contains(appRelativeVirtualPath))
            {
                // create new fake BuildManagerCacheItem wich represent the target type
                var buildManagerCacheItemType = Type.GetType("System.Web.Compilation.BuildManagerCacheItem, System.Web");
                var cacheItemCtor             = buildManagerCacheItemType.GetConstructor(new Type[] { typeof(Assembly), typeof(BuildProvider), typeof(CompilerResults) });
                var buildProvider             = new FakeBuildProvider(serviceType);
                var cacheItem = cacheItemCtor.Invoke(new object[] { serviceType.Assembly, buildProvider, null });

                // store it in the BuildManager
                buildCache [appRelativeVirtualPath] = cacheItem;
            }

            // now that the target type is in the cache, let the default process continue
            return(base.GetHandler(context, requestType, url, path));
#endif
        }
        /// <summary>
        /// Retrieves instance of the page from Spring web application context.
        /// </summary>
        /// <param name="context">current HttpContext</param>
        /// <param name="requestType">type of HTTP request (GET, POST, etc.)</param>
        /// <param name="url">requested page URL</param>
        /// <param name="path">translated server path for the page</param>
        /// <returns>instance of the configured page object</returns>
        IHttpHandler IHttpHandlerFactory.GetHandler(HttpContext context, string requestType, string url, string path)
        {
            new AspNetHostingPermission(AspNetHostingPermissionLevel.Minimal).Demand();

            IConfigurableApplicationContext appContext =
                WebApplicationContext.GetContext(url) as IConfigurableApplicationContext;
            
            if (appContext == null)
            {
                throw new InvalidOperationException(
                    "Implementations of IApplicationContext must also implement IConfigurableApplicationContext");
            }

            string appRelativeVirtualPath = WebUtils.GetAppRelativePath(url);

            AbstractHandlerFactory.NamedObjectDefinition nod =
                AbstractHandlerFactory.FindWebObjectDefinition(appRelativeVirtualPath, appContext.ObjectFactory);

            Type serviceType = null;
            if (nod != null)
            {
#if !MONO
                if (appContext.IsTypeMatch(nod.Name, typeof(WebServiceExporter)))
                {
                    WebServiceExporter wse = (WebServiceExporter)appContext.GetObject(nod.Name);
                    serviceType = wse.GetExportedType();
                }
                else
                {
                    serviceType = appContext.GetType(nod.Name);
                    // check if the type defines a Web Service
                    object[] wsAttribute = serviceType.GetCustomAttributes(typeof(WebServiceAttribute), true);
                    if (wsAttribute.Length == 0)
                    {
                        serviceType = null;
                    }
                }
#else
                serviceType = appContext.GetType(nod.Name);

                // check if the type defines a Web Service
                object[] wsAttribute = serviceType.GetCustomAttributes(typeof(WebServiceAttribute), true);
                if (wsAttribute.Length == 0)
                {
                    serviceType = null;
                }  
#endif
            }

            if (serviceType == null)
            {
#if NET_2_0
                serviceType = WebServiceParser.GetCompiledType(url, context);
#else
                serviceType = WebServiceParser.GetCompiledType(path, context);
#endif
            }
			

#if !MONO_2_0
            return (IHttpHandler) CoreGetHandler.Invoke(this, new object[] {serviceType, context, context.Request, context.Response});
#else		

			// find if the BuildManager already contains a cached value of the service type
			var buildCacheField = typeof(BuildManager).GetField("buildCache", BindingFlags.Static | BindingFlags.NonPublic);
			var buildCache = (IDictionary)buildCacheField.GetValue(null);
			
			if(!buildCache.Contains(appRelativeVirtualPath))
			{
				// create new fake BuildManagerCacheItem wich represent the target type
				var buildManagerCacheItemType = Type.GetType("System.Web.Compilation.BuildManagerCacheItem, System.Web");
				var cacheItemCtor = buildManagerCacheItemType.GetConstructor(new Type[]{typeof(Assembly), typeof(BuildProvider), typeof(CompilerResults)});
				var buildProvider = new FakeBuildProvider(serviceType);
				var cacheItem = cacheItemCtor.Invoke(new object[]{serviceType.Assembly, buildProvider, null });
					
				// store it in the BuildManager
				buildCache [appRelativeVirtualPath] = cacheItem;
			}
			
			// now that the target type is in the cache, let the default process continue
			return base.GetHandler(context, requestType, url, path);			
#endif
        }