/// <summary> /// Retrieves an instance of the <see cref="System.Web.IHttpHandler"/> /// implementation for handling web service requests /// for both Spring and ASP.NET AJAX 1.0 web services. /// </summary> /// <param name="context">The current HTTP context.</param> /// <param name="requestType">The type of HTTP request (GET or POST).</param> /// <param name="url">The url of the web service.</param> /// <param name="pathTranslated">The physical application path for the web service.</param> /// <returns>The web service handler object.</returns> public override IHttpHandler GetHandler(HttpContext context, string requestType, string url, string pathTranslated) { string filename = VirtualPathUtility.ToAbsolute(context.Request.FilePath); string cacheKey = (string)webServiceData_GetCacheKey.Invoke(null, new object[] { filename }); object webServiceData = context.Cache.Get(cacheKey); if (webServiceData == null) { IConfigurableApplicationContext appContext = base.GetCheckedApplicationContext(url); string appRelativeVirtualPath = WebUtils.GetAppRelativePath(url); NamedObjectDefinition nod = FindWebObjectDefinition(appRelativeVirtualPath, appContext.ObjectFactory); if (nod != null) { Type serviceType = null; if (appContext.IsTypeMatch(nod.Name, typeof(WebServiceExporter))) { WebServiceExporter wse = (WebServiceExporter)appContext.GetObject(nod.Name); serviceType = wse.GetExportedType(); } else { serviceType = appContext.GetType(nod.Name); } object[] attrs = serviceType.GetCustomAttributes(typeof(ScriptServiceAttribute), false); if (attrs.Length > 0) { webServiceData = webServiceData_ctor.Invoke(new object[] { serviceType, false }); context.Cache.Insert(cacheKey, webServiceData); } } } return(this.scriptHandlerFactory.GetHandler(context, requestType, url, pathTranslated)); }
/// <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 }