Ejemplo n.º 1
0
        internal static WebServiceDef GetWebServiceType(HttpContext context, string virtualPath)
        {
            virtualPath = VirtualPathUtility.ToAbsolute(virtualPath.Replace(".soap", ".asmx"));

            string        cacheKey = GetCacheKey(virtualPath);
            WebServiceDef wsType   = context.Cache[cacheKey] as WebServiceDef;

            if (wsType == null)
            {
                if (HostingEnvironment.VirtualPathProvider.FileExists(virtualPath))
                {
                    Type compiledType = null;
                    try
                    {
                        compiledType = BuildManager.GetCompiledType(virtualPath);


                        if (compiledType == null)
                        {
                            object page = BuildManager.CreateInstanceFromVirtualPath(virtualPath, typeof(System.Web.UI.Page));
                            compiledType = page.GetType();
                        }
                    }
                    catch (SecurityException)
                    {
                    }

                    if (compiledType != null)
                    {
                        wsType = new WebServiceDef(compiledType);
                        BuildDependencySet deps         = BuildManager.GetCachedBuildDependencySet(context, virtualPath);
                        IEnumerable        virtualPaths = deps.VirtualPaths;
                        if (virtualPaths != null)
                        {
                            List <string> paths = new List <string>();
                            foreach (string path in virtualPaths)
                            {
                                paths.Add(Path.Combine(context.Request.PhysicalApplicationPath, VirtualPathUtility.GetFileName(path)));
                            }
                            context.Cache.Insert(cacheKey, wsType, new CacheDependency(paths.ToArray()));
                        }
                        else
                        {
                            context.Cache.Insert(cacheKey, wsType);
                        }
                    }
                }
            }

            if (wsType == null)
            {
                throw new InvalidOperationException("Webservice does not exist");
            }

            return(wsType);
        }
Ejemplo n.º 2
0
        private static void PutToCache(string path, HttpContext context, string cacheKey, HandlerMethods handlerMethods)
        {
            BuildDependencySet dependencySet = BuildManager.GetCachedBuildDependencySet(context, path);

            if (dependencySet != null)
            {
                IEnumerable virtualPaths = dependencySet.VirtualPaths;
                if (virtualPaths != null)
                {
                    List <string> paths = new List <string>();
                    foreach (string _path in virtualPaths)
                    {
                        paths.Add(context.Server.MapPath(_path));
                    }
                    context.Cache.Insert(cacheKey, handlerMethods, new CacheDependency(paths.ToArray()));
                    return;
                }
            }

            context.Cache.Insert(cacheKey, handlerMethods);
        }
Ejemplo n.º 3
0
        internal static WebServiceData GetWebServiceData(HttpContext context, string virtualPath, bool failIfNoData, bool pageMethods, bool inlineScript)
        {
            // Make sure the path is cannonical to avoid doing more work than necessary
            virtualPath = VirtualPathUtility.ToAbsolute(virtualPath);

            string         cacheKey = GetCacheKey(virtualPath);
            WebServiceData data     = context.Cache[cacheKey] as WebServiceData;

            // Handle the case where the virtualPath exists, for example a real asmx page.
            if (data == null)
            {
                if (HostingEnvironment.VirtualPathProvider.FileExists(virtualPath))
                {
                    Type compiledType = null;
                    try {
                        compiledType = BuildManager.GetCompiledType(virtualPath);

                        // If we can't get the compiled type, try creating an instance (i.e. for no compile pages)
                        if (compiledType == null)
                        {
                            object page = BuildManager.CreateInstanceFromVirtualPath(virtualPath, typeof(System.Web.UI.Page));
                            if (page != null)
                            {
                                compiledType = page.GetType();
                            }
                        }
                    }
                    catch (SecurityException) {
                        // DevDiv 33708: BuildManager requires Medium trust, so we need to no-op rather than
                        // destroying the page.
                    }

                    if (compiledType != null)
                    {
                        data = new WebServiceData(compiledType, pageMethods);
                        BuildDependencySet deps = BuildManager.GetCachedBuildDependencySet(context, virtualPath);
                        if (deps != null)
                        {
                            // Dev10 718863: It's possible 'deps' is null if the service is modified between GetCompiledType and here.
                            // in that case simply do not cache the result so it is re-established next time it is required.
                            CacheDependency cd = HostingEnvironment.VirtualPathProvider.GetCacheDependency(virtualPath, deps.VirtualPaths, DateTime.Now);
                            context.Cache.Insert(cacheKey, data, cd);
                        }
                    }
                }
                else if (virtualPath.EndsWith("_AppService.axd", StringComparison.OrdinalIgnoreCase))
                {
                    // File does not exist, but the url may be a request for one of the three built-in services: ProfileService, AuthenticationService, RoleService
                    data = WebServiceData.GetApplicationService(context.Request.AppRelativeCurrentExecutionFilePath);
                    if (data != null)
                    {
                        context.Cache.Insert(cacheKey, data);
                    }
                }
            }

            if (data == null)
            {
                if (failIfNoData)
                {
                    if (inlineScript)
                    {
                        //DevDiv 74432: InlineScript = true fails, for WCF serviceReferences: Need an appropriate error message
                        throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture, AtlasWeb.WebService_NoWebServiceDataInlineScript, virtualPath));
                    }
                    else
                    {
                        throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture, AtlasWeb.WebService_NoWebServiceData, virtualPath));
                    }
                }
                else
                {
                    return(null);
                }
            }

            return(data);
        }