Esempio n. 1
0
        /// <include file='doc\WebServiceHandlerFactory.uex' path='docs/doc[@for="WebServiceHandlerFactory.GetHandler"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public IHttpHandler GetHandler(HttpContext context, string verb, string url, string filePath)
        {
            TraceMethod method = Tracing.On ? new TraceMethod(this, "GetHandler") : null;

            if (Tracing.On)
            {
                Tracing.Enter("IHttpHandlerFactory.GetHandler", method, Tracing.Details(context.Request));
            }

            new AspNetHostingPermission(AspNetHostingPermissionLevel.Minimal).Demand();
            //if (CompModSwitches.Remote.TraceVerbose) DumpRequest(context);
            //System.Diagnostics.Debugger.Break();
#if DEBUG
            if (CompModSwitches.Remote.TraceVerbose)
            {
                DumpRequest(context);
            }
#endif

            Type         type    = GetCompiledType(url, context);
            IHttpHandler handler = CoreGetHandler(type, context, context.Request, context.Response);

            if (Tracing.On)
            {
                Tracing.Exit("IHttpHandlerFactory.GetHandler", method);
            }

            return(handler);
        }
Esempio n. 2
0
        public void ProcessRequest(HttpContext context)
        {
            TraceMethod caller = Tracing.On ? new TraceMethod(this, "ProcessRequest", new object[0]) : null;

            if (Tracing.On)
            {
                Tracing.Enter("IHttpHandler.ProcessRequest", caller, Tracing.Details(context.Request));
            }
            base.CoreProcessRequest();
            if (Tracing.On)
            {
                Tracing.Exit("IHttpHandler.ProcessRequest", caller);
            }
        }
Esempio n. 3
0
        public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback callback, object asyncState)
        {
            TraceMethod caller = Tracing.On ? new TraceMethod(this, "BeginProcessRequest", new object[0]) : null;

            if (Tracing.On)
            {
                Tracing.Enter("IHttpAsyncHandler.BeginProcessRequest", caller, Tracing.Details(context.Request));
            }
            IAsyncResult result = base.BeginCoreProcessRequest(callback, asyncState);

            if (Tracing.On)
            {
                Tracing.Exit("IHttpAsyncHandler.BeginProcessRequest", caller);
            }
            return(result);
        }
        public void ProcessRequest(HttpContext context)
        {
            TraceMethod method = Tracing.On ? new TraceMethod(this, "ProcessRequest") : null;

            if (Tracing.On)
            {
                Tracing.Enter("IHttpHandler.ProcessRequest", method, Tracing.Details(context.Request));
            }

            CoreProcessRequest();

            if (Tracing.On)
            {
                Tracing.Exit("IHttpHandler.ProcessRequest", method);
            }
        }
Esempio n. 5
0
        public IHttpHandler GetHandler(HttpContext context, string verb, string url, string filePath)
        {
            TraceMethod caller = Tracing.On ? new TraceMethod(this, "GetHandler", new object[0]) : null;

            if (Tracing.On)
            {
                Tracing.Enter("IHttpHandlerFactory.GetHandler", caller, Tracing.Details(context.Request));
            }
            new AspNetHostingPermission(AspNetHostingPermissionLevel.Minimal).Demand();
            Type         compiledType = this.GetCompiledType(url, context);
            IHttpHandler handler      = this.CoreGetHandler(compiledType, context, context.Request, context.Response);

            if (Tracing.On)
            {
                Tracing.Exit("IHttpHandlerFactory.GetHandler", caller);
            }
            return(handler);
        }
        /// <include file='doc\DiscoveryRequestHandler.uex' path='docs/doc[@for="DiscoveryRequestHandler.ProcessRequest"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public void ProcessRequest(HttpContext context)
        {
            TraceMethod method = Tracing.On ? new TraceMethod(this, "ProcessRequest") : null;

            if (Tracing.On)
            {
                Tracing.Enter("IHttpHandler.ProcessRequest", method, Tracing.Details(context.Request));
            }

            new PermissionSet(PermissionState.Unrestricted).Demand();
            // string cacheKey;

            string physicalPath = context.Request.PhysicalPath;

            if (CompModSwitches.DynamicDiscoverySearcher.TraceVerbose)
            {
                Debug.WriteLine("DiscoveryRequestHandle: handling " + physicalPath);
            }

            // Check to see if file exists locally.
            if (File.Exists(physicalPath))
            {
                DynamicDiscoveryDocument dynDisco = null;
                FileStream stream = null;
                try {
                    stream = new FileStream(physicalPath, FileMode.Open, FileAccess.Read);
                    XmlTextReader xmlReader = new XmlTextReader(stream);
                    xmlReader.WhitespaceHandling = WhitespaceHandling.Significant;
                    xmlReader.XmlResolver        = null;
                    xmlReader.DtdProcessing      = DtdProcessing.Prohibit;
                    if (xmlReader.IsStartElement("dynamicDiscovery", DynamicDiscoveryDocument.Namespace))
                    {
                        stream.Position = 0;
                        dynDisco        = DynamicDiscoveryDocument.Load(stream);
                    }
                }
                finally {
                    if (stream != null)
                    {
                        stream.Close();
                    }
                }

                if (dynDisco != null)
                {
                    string[] excludeList        = new string[dynDisco.ExcludePaths.Length];
                    string   discoFileDirectory = Path.GetDirectoryName(physicalPath);
                    string   discoFileName      = Path.GetFileName(physicalPath);

                    for (int i = 0; i < excludeList.Length; i++)
                    {
                        // Exclude list now consists of relative paths, so this transformation not needed.
                        // excludeList[i] = Path.Combine(discoFileDirectory, dynDisco.ExcludePaths[i].Path);
                        excludeList[i] = dynDisco.ExcludePaths[i].Path;
                    }

                    // Determine start url path for search
                    DynamicDiscoSearcher searcher;
                    Uri    searchStartUrl    = context.Request.Url;
                    string escapedUri        = RuntimeUtils.EscapeUri(searchStartUrl);
                    string searchStartUrlDir = GetDirPartOfPath(escapedUri);    // URL path without file name
                    string strLocalPath      = GetDirPartOfPath(searchStartUrl.LocalPath);

                    if (strLocalPath.Length == 0 ||                           // no subdir present, host only
                        CompModSwitches.DynamicDiscoveryVirtualSearch.Enabled // virtual search forced (for test suites).
                        )
                    {
                        discoFileName = GetFilePartOfPath(escapedUri);
                        searcher      = new DynamicVirtualDiscoSearcher(discoFileDirectory, excludeList, searchStartUrlDir);
                    }
                    else
                    {
                        searcher = new DynamicPhysicalDiscoSearcher(discoFileDirectory, excludeList, searchStartUrlDir);
                    }

                    if (CompModSwitches.DynamicDiscoverySearcher.TraceVerbose)
                    {
                        Debug.WriteLine("*** DiscoveryRequestHandler.ProcessRequest() - startDir: " + searchStartUrlDir + " discoFileName :" + discoFileName);
                    }
                    searcher.Search(discoFileName);

                    DiscoveryDocument discoFile = searcher.DiscoveryDocument;

                    MemoryStream memStream = new MemoryStream(1024);
                    StreamWriter writer    = new StreamWriter(memStream, new UTF8Encoding(false));
                    discoFile.Write(writer);
                    memStream.Position = 0;
                    byte[] data      = new byte[(int)memStream.Length];
                    int    bytesRead = memStream.Read(data, 0, data.Length);
                    context.Response.ContentType = ContentType.Compose("text/xml", Encoding.UTF8);
                    context.Response.OutputStream.Write(data, 0, bytesRead);
                }
                else
                {
                    // Else, just return the disco file
                    context.Response.ContentType = "text/xml";
                    context.Response.WriteFile(physicalPath);
                }
                if (Tracing.On)
                {
                    Tracing.Exit("IHttpHandler.ProcessRequest", method);
                }
                return;
            }
            if (Tracing.On)
            {
                Tracing.Exit("IHttpHandler.ProcessRequest", method);
            }

            // Else, file is not found
            throw new HttpException(404, Res.GetString(Res.WebPathNotFound, context.Request.Path));
        }
        internal override SoapServerMethod RouteRequest()
        {
            object methodKey;

            string methodUriString = ServerProtocol.Request.Headers[Soap.Action];

            if (methodUriString == null)
            {
                throw new SoapException(Res.GetString(Res.UnableToHandleRequestActionRequired0), new XmlQualifiedName(Soap.Code.Client, Soap.Namespace));
            }

            if (ServerType.routingOnSoapAction)
            {
                if (methodUriString.StartsWith("\"", StringComparison.Ordinal) && methodUriString.EndsWith("\"", StringComparison.Ordinal))
                {
                    methodUriString = methodUriString.Substring(1, methodUriString.Length - 2);
                }

                methodKey = HttpUtility.UrlDecode(methodUriString);
            }
            else
            {
                try {
                    methodKey = GetRequestElement();
                }
                catch (SoapException) {
                    throw;
                }
                catch (Exception e) {
                    if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException)
                    {
                        throw;
                    }
                    throw new SoapException(Res.GetString(Res.TheRootElementForTheRequestCouldNotBeDetermined0), new XmlQualifiedName(Soap.Code.Server, Soap.Namespace), e);
                }
            }

            TraceMethod caller = Tracing.On ? new TraceMethod(this, "RouteRequest") : null;

            if (Tracing.On)
            {
                Tracing.Enter("RouteRequest", caller, new TraceMethod(ServerType, "GetMethod", methodKey), Tracing.Details(ServerProtocol.Request));
            }
            SoapServerMethod method = ServerType.GetMethod(methodKey);

            if (Tracing.On)
            {
                Tracing.Exit("RouteRequest", caller);
            }

            if (method == null)
            {
                if (ServerType.routingOnSoapAction)
                {
                    throw new SoapException(Res.GetString(Res.WebHttpHeader, Soap.Action, (string)methodKey), new XmlQualifiedName(Soap.Code.Client, Soap.Namespace));
                }
                else
                {
                    throw new SoapException(Res.GetString(Res.TheRequestElementXmlnsWasNotRecognized2, ((XmlQualifiedName)methodKey).Name, ((XmlQualifiedName)methodKey).Namespace), new XmlQualifiedName(Soap.Code.Client, Soap.Namespace));
                }
            }

            return(method);
        }
        public void ProcessRequest(HttpContext context)
        {
            TraceMethod caller = Tracing.On ? new TraceMethod(this, "ProcessRequest", new object[0]) : null;

            if (Tracing.On)
            {
                Tracing.Enter("IHttpHandler.ProcessRequest", caller, Tracing.Details(context.Request));
            }
            new PermissionSet(PermissionState.Unrestricted).Demand();
            string physicalPath = context.Request.PhysicalPath;
            bool   traceVerbose = System.ComponentModel.CompModSwitches.DynamicDiscoverySearcher.TraceVerbose;

            if (File.Exists(physicalPath))
            {
                DynamicDiscoveryDocument document = null;
                FileStream input = null;
                try
                {
                    input = new FileStream(physicalPath, FileMode.Open, FileAccess.Read);
                    XmlTextReader reader = new XmlTextReader(input)
                    {
                        WhitespaceHandling = WhitespaceHandling.Significant,
                        XmlResolver        = null,
                        DtdProcessing      = DtdProcessing.Prohibit
                    };
                    if (reader.IsStartElement("dynamicDiscovery", "urn:schemas-dynamicdiscovery:disco.2000-03-17"))
                    {
                        input.Position = 0L;
                        document       = DynamicDiscoveryDocument.Load(input);
                    }
                }
                finally
                {
                    if (input != null)
                    {
                        input.Close();
                    }
                }
                if (document != null)
                {
                    DynamicDiscoSearcher searcher;
                    string[]             excludedUrls = new string[document.ExcludePaths.Length];
                    string directoryName = Path.GetDirectoryName(physicalPath);
                    string fileName      = Path.GetFileName(physicalPath);
                    for (int i = 0; i < excludedUrls.Length; i++)
                    {
                        excludedUrls[i] = document.ExcludePaths[i].Path;
                    }
                    Uri    url           = context.Request.Url;
                    string str           = Uri.EscapeUriString(url.ToString()).Replace("#", "%23");
                    string dirPartOfPath = GetDirPartOfPath(str);
                    if ((GetDirPartOfPath(url.LocalPath).Length == 0) || System.ComponentModel.CompModSwitches.DynamicDiscoveryVirtualSearch.Enabled)
                    {
                        fileName = GetFilePartOfPath(str);
                        searcher = new DynamicVirtualDiscoSearcher(directoryName, excludedUrls, dirPartOfPath);
                    }
                    else
                    {
                        searcher = new DynamicPhysicalDiscoSearcher(directoryName, excludedUrls, dirPartOfPath);
                    }
                    bool flag2 = System.ComponentModel.CompModSwitches.DynamicDiscoverySearcher.TraceVerbose;
                    searcher.Search(fileName);
                    DiscoveryDocument discoveryDocument = searcher.DiscoveryDocument;
                    MemoryStream      stream            = new MemoryStream(0x400);
                    StreamWriter      writer            = new StreamWriter(stream, new UTF8Encoding(false));
                    discoveryDocument.Write(writer);
                    stream.Position = 0L;
                    byte[] buffer = new byte[(int)stream.Length];
                    int    count  = stream.Read(buffer, 0, buffer.Length);
                    context.Response.ContentType = ContentType.Compose("text/xml", Encoding.UTF8);
                    context.Response.OutputStream.Write(buffer, 0, count);
                }
                else
                {
                    context.Response.ContentType = "text/xml";
                    context.Response.WriteFile(physicalPath);
                }
                if (Tracing.On)
                {
                    Tracing.Exit("IHttpHandler.ProcessRequest", caller);
                }
            }
            else
            {
                if (Tracing.On)
                {
                    Tracing.Exit("IHttpHandler.ProcessRequest", caller);
                }
                throw new HttpException(0x194, System.Web.Services.Res.GetString("WebPathNotFound", new object[] { context.Request.Path }));
            }
        }
Esempio n. 9
0
        internal override SoapServerMethod RouteRequest()
        {
            string action = ContentType.GetAction(ServerProtocol.Request.ContentType);

            SoapServerMethod method = null;
            bool             duplicateAction = false, duplicateRequestElement = false;

            TraceMethod caller = Tracing.On ? new TraceMethod(this, "RouteRequest") : null;

            if (action != null && action.Length > 0)
            {
                action = HttpUtility.UrlDecode(action);
                if (Tracing.On)
                {
                    Tracing.Enter("RouteRequest", caller, new TraceMethod(ServerType, "GetMethod", action), Tracing.Details(ServerProtocol.Request));
                }
                method = ServerType.GetMethod(action);
                if (Tracing.On)
                {
                    Tracing.Exit("RouteRequest", caller);
                }
                if (method != null)
                {
                    if (ServerType.GetDuplicateMethod(action) != null)
                    {
                        method          = null;
                        duplicateAction = true;
                    }
                }
            }

            XmlQualifiedName requestElement = XmlQualifiedName.Empty;

            if (method == null)
            {
                // try request element
                requestElement = GetRequestElement();
                if (Tracing.On)
                {
                    Tracing.Enter("RouteRequest", caller, new TraceMethod(ServerType, "GetMethod", requestElement), Tracing.Details(ServerProtocol.Request));
                }
                method = ServerType.GetMethod(requestElement);
                if (Tracing.On)
                {
                    Tracing.Exit("RouteRequest", caller);
                }
                if (method != null)
                {
                    if (ServerType.GetDuplicateMethod(requestElement) != null)
                    {
                        method = null;
                        duplicateRequestElement = true;
                    }
                }
            }

            if (method == null)
            {
                // try to figure out what happened...
                if (action == null || action.Length == 0)
                {
                    // they didn't send a soap action and we couldn't route on request element
                    // require soap action for future requests:
                    throw new SoapException(Res.GetString(Res.UnableToHandleRequestActionRequired0), Soap12FaultCodes.SenderFaultCode);
                }
                else if (duplicateAction)
                {
                    // what went wrong with the request element?
                    if (duplicateRequestElement)
                    {
                        // server's fault -- nothing the client could have done to prevent this
                        throw new SoapException(Res.GetString(Res.UnableToHandleRequest0), Soap12FaultCodes.ReceiverFaultCode);
                    }
                    else
                    {
                        // probably client's fault -- we didn't recognize the request element they sent
                        throw new SoapException(Res.GetString(Res.TheRequestElementXmlnsWasNotRecognized2, requestElement.Name, requestElement.Namespace), Soap12FaultCodes.SenderFaultCode);
                    }
                }
                else
                {
                    // neither action nor request element worked out for us. since they sent an action,
                    // we'll suggest they do a better job next time
                    throw new SoapException(Res.GetString(Res.UnableToHandleRequestActionNotRecognized1, action), Soap12FaultCodes.SenderFaultCode);
                }
            }

            return(method);
        }
Esempio n. 10
0
        internal override SoapServerMethod RouteRequest()
        {
            string           action = ContentType.GetAction(base.ServerProtocol.Request.ContentType);
            SoapServerMethod method = null;
            bool             flag   = false;
            bool             flag2  = false;
            TraceMethod      caller = Tracing.On ? new TraceMethod(this, "RouteRequest", new object[0]) : null;

            if ((action != null) && (action.Length > 0))
            {
                action = System.Web.HttpUtility.UrlDecode(action);
                if (Tracing.On)
                {
                    Tracing.Enter("RouteRequest", caller, new TraceMethod(base.ServerType, "GetMethod", new object[] { action }), Tracing.Details(base.ServerProtocol.Request));
                }
                method = base.ServerType.GetMethod(action);
                if (Tracing.On)
                {
                    Tracing.Exit("RouteRequest", caller);
                }
                if ((method != null) && (base.ServerType.GetDuplicateMethod(action) != null))
                {
                    method = null;
                    flag   = true;
                }
            }
            XmlQualifiedName empty = XmlQualifiedName.Empty;

            if (method == null)
            {
                empty = base.GetRequestElement();
                if (Tracing.On)
                {
                    Tracing.Enter("RouteRequest", caller, new TraceMethod(base.ServerType, "GetMethod", new object[] { empty }), Tracing.Details(base.ServerProtocol.Request));
                }
                method = base.ServerType.GetMethod(empty);
                if (Tracing.On)
                {
                    Tracing.Exit("RouteRequest", caller);
                }
                if ((method != null) && (base.ServerType.GetDuplicateMethod(empty) != null))
                {
                    method = null;
                    flag2  = true;
                }
            }
            if (method != null)
            {
                return(method);
            }
            if ((action == null) || (action.Length == 0))
            {
                throw new SoapException(System.Web.Services.Res.GetString("UnableToHandleRequestActionRequired0"), Soap12FaultCodes.SenderFaultCode);
            }
            if (flag)
            {
                if (flag2)
                {
                    throw new SoapException(System.Web.Services.Res.GetString("UnableToHandleRequest0"), Soap12FaultCodes.ReceiverFaultCode);
                }
                throw new SoapException(System.Web.Services.Res.GetString("TheRequestElementXmlnsWasNotRecognized2", new object[] { empty.Name, empty.Namespace }), Soap12FaultCodes.SenderFaultCode);
            }
            throw new SoapException(System.Web.Services.Res.GetString("UnableToHandleRequestActionNotRecognized1", new object[] { action }), Soap12FaultCodes.SenderFaultCode);
        }
        internal override SoapServerMethod RouteRequest()
        {
            object requestElement;
            string str = base.ServerProtocol.Request.Headers["SOAPAction"];

            if (str == null)
            {
                throw new SoapException(System.Web.Services.Res.GetString("UnableToHandleRequestActionRequired0"), new XmlQualifiedName("Client", "http://schemas.xmlsoap.org/soap/envelope/"));
            }
            if (base.ServerType.routingOnSoapAction)
            {
                if (str.StartsWith("\"", StringComparison.Ordinal) && str.EndsWith("\"", StringComparison.Ordinal))
                {
                    str = str.Substring(1, str.Length - 2);
                }
                requestElement = System.Web.HttpUtility.UrlDecode(str);
            }
            else
            {
                try
                {
                    requestElement = base.GetRequestElement();
                }
                catch (SoapException)
                {
                    throw;
                }
                catch (Exception exception)
                {
                    if (((exception is ThreadAbortException) || (exception is StackOverflowException)) || (exception is OutOfMemoryException))
                    {
                        throw;
                    }
                    throw new SoapException(System.Web.Services.Res.GetString("TheRootElementForTheRequestCouldNotBeDetermined0"), new XmlQualifiedName("Server", "http://schemas.xmlsoap.org/soap/envelope/"), exception);
                }
            }
            TraceMethod caller = Tracing.On ? new TraceMethod(this, "RouteRequest", new object[0]) : null;

            if (Tracing.On)
            {
                Tracing.Enter("RouteRequest", caller, new TraceMethod(base.ServerType, "GetMethod", new object[] { requestElement }), Tracing.Details(base.ServerProtocol.Request));
            }
            SoapServerMethod method = base.ServerType.GetMethod(requestElement);

            if (Tracing.On)
            {
                Tracing.Exit("RouteRequest", caller);
            }
            if (method != null)
            {
                return(method);
            }
            if (base.ServerType.routingOnSoapAction)
            {
                throw new SoapException(System.Web.Services.Res.GetString("WebHttpHeader", new object[] { "SOAPAction", (string)requestElement }), new XmlQualifiedName("Client", "http://schemas.xmlsoap.org/soap/envelope/"));
            }
            throw new SoapException(System.Web.Services.Res.GetString("TheRequestElementXmlnsWasNotRecognized2", new object[] { ((XmlQualifiedName)requestElement).Name, ((XmlQualifiedName)requestElement).Namespace }), new XmlQualifiedName("Client", "http://schemas.xmlsoap.org/soap/envelope/"));
        }