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.ClientCode, Soap.Namespace));
            }

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

                methodKey = HttpUtility.UrlDecode(methodUriString);
            }
            else
            {
                try {
                    methodKey = GetRequestElement();
                }
                catch (SoapException) {
                    throw;
                }
                catch (Exception e) {
                    throw new SoapException(Res.GetString(Res.TheRootElementForTheRequestCouldNotBeDetermined0), new XmlQualifiedName(Soap.ServerCode, Soap.Namespace), e);
                }
            }

            SoapServerMethod method = ServerType.GetMethod(methodKey);

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

            return(method);
        }
        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);
        }
Exemplo n.º 3
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);
        }