internal ServerProtocol Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, out bool abortProcessing)
        {
            ServerProtocol protocol = null;

            abortProcessing = false;
            protocol        = this.CreateIfRequestCompatible(request);
            try
            {
                if (protocol != null)
                {
                    protocol.SetContext(type, context, request, response);
                }
                return(protocol);
            }
            catch (Exception exception)
            {
                abortProcessing = true;
                if (((exception is ThreadAbortException) || (exception is StackOverflowException)) || (exception is OutOfMemoryException))
                {
                    throw;
                }
                if (Tracing.On)
                {
                    Tracing.ExceptionCatch(TraceEventType.Warning, this, "Create", exception);
                }
                if ((protocol != null) && !protocol.WriteException(exception, protocol.Response.OutputStream))
                {
                    throw new InvalidOperationException(Res.GetString("UnableToHandleRequest0"), exception);
                }
                return(null);
            }
        }
Beispiel #2
0
        internal static bool IsServerCallInEnabled(ServerProtocol protocol, out string stringBuffer)
        {
            stringBuffer = null;
            bool enabled = false;

            try {
                if (CompModSwitches.DisableRemoteDebugging.Enabled)
                {
                    return(false);
                }

                enabled = protocol.Context.IsDebuggingEnabled && Connection != null;
                if (enabled)
                {
                    stringBuffer = protocol.Request.Headers[debuggerHeader];
                    enabled      = (stringBuffer != null && stringBuffer.Length > 0);
                }
            }
            catch (Exception e) {
                if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException)
                {
                    throw;
                }
                if (Tracing.On)
                {
                    Tracing.ExceptionCatch(TraceEventType.Warning, typeof(RemoteDebugger), "IsServerCallInEnabled", e);
                }
                enabled = false;
            }
            return(enabled);
        }
Beispiel #3
0
        internal ServerProtocol Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, out bool abortProcessing)
        {
            ServerProtocol serverProtocol = null;

            abortProcessing = false;
            serverProtocol  = CreateIfRequestCompatible(request);
            try {
                if (serverProtocol != null)
                {
                    serverProtocol.SetContext(type, context, request, response);
                }
                return(serverProtocol);
            }
            catch (Exception e) {
                abortProcessing = true;
                if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException)
                {
                    throw;
                }
                if (Tracing.On)
                {
                    Tracing.ExceptionCatch(TraceEventType.Warning, this, "Create", e);
                }
                if (serverProtocol != null)
                {
                    // give the protocol a shot at handling the error in a custom way
                    if (!serverProtocol.WriteException(e, serverProtocol.Response.OutputStream))
                    {
                        throw new InvalidOperationException(Res.GetString(Res.UnableToHandleRequest0), e);
                    }
                }
                return(null);
            }
        }
Beispiel #4
0
        internal static bool IsServerCallInEnabled(ServerProtocol protocol, out string stringBuffer)
        {
            stringBuffer = null;
            bool flag = false;

            try
            {
                if (System.ComponentModel.CompModSwitches.DisableRemoteDebugging.Enabled)
                {
                    return(false);
                }
                flag = protocol.Context.IsDebuggingEnabled && (Connection != null);
                if (flag)
                {
                    stringBuffer = protocol.Request.Headers[debuggerHeader];
                    flag         = (stringBuffer != null) && (stringBuffer.Length > 0);
                }
            }
            catch (Exception exception)
            {
                if (((exception is ThreadAbortException) || (exception is StackOverflowException)) || (exception is OutOfMemoryException))
                {
                    throw;
                }
                if (Tracing.On)
                {
                    Tracing.ExceptionCatch(TraceEventType.Warning, typeof(RemoteDebugger), "IsServerCallInEnabled", exception);
                }
                flag = false;
            }
            return(flag);
        }
        internal void NotifyServerCallEnter(ServerProtocol protocol, string stringBuffer)
        {
            try {
                if (NotifySink == null)
                {
                    return;
                }
                StringBuilder methodBuilder = new StringBuilder();
                methodBuilder.Append(protocol.Type.FullName);
                methodBuilder.Append('.');
                methodBuilder.Append(protocol.MethodInfo.Name);
                methodBuilder.Append('(');
                ParameterInfo[] parameterInfos = protocol.MethodInfo.Parameters;
                for (int i = 0; i < parameterInfos.Length; ++i)
                {
                    if (i != 0)
                    {
                        methodBuilder.Append(',');
                    }

                    methodBuilder.Append(parameterInfos[i].ParameterType.FullName);
                }
                methodBuilder.Append(')');

                byte[] buffer = Convert.FromBase64String(stringBuffer);
                CallId callId = new CallId(null, 0, (IntPtr)0, 0, methodBuilder.ToString(), null);
                UnsafeNativeMethods.OnSyncCallEnter(NotifySink, callId, buffer, buffer.Length);
            }
            catch (Exception) {
            }
        }
        internal ServerProtocol Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, out bool abortProcessing)
        {
            ServerProtocol serverProtocol = null;

            abortProcessing = false;
            try {
                serverProtocol = CreateIfRequestCompatible(request);
                if (serverProtocol != null)
                {
                    serverProtocol.SetContext(type, context, request, response);
                }
                return(serverProtocol);
            }
            catch (Exception e) {
                abortProcessing = true;
                if (serverProtocol != null)
                {
                    // give the protocol a shot at handling the error in a custom way
                    if (!serverProtocol.WriteException(e, serverProtocol.Response.OutputStream))
                    {
                        throw new InvalidOperationException(Res.GetString(Res.UnableToHandleRequest0), e);
                    }
                }
                return(null);
            }
        }
Beispiel #7
0
        internal IHttpHandler CoreGetHandler(Type type, HttpContext context, HttpRequest request, HttpResponse response)
        {
            TraceMethod method = Tracing.On ? new TraceMethod(this, "CoreGetHandler", new object[0]) : null;

            ServerProtocolFactory[] serverProtocolFactories = this.GetServerProtocolFactories();
            ServerProtocol          protocol = null;
            bool abortProcessing             = false;

            for (int i = 0; i < serverProtocolFactories.Length; i++)
            {
                try
                {
                    protocol = serverProtocolFactories[i].Create(type, context, request, response, out abortProcessing);
                    if (((protocol != null) && (protocol.GetType() != typeof(UnsupportedRequestProtocol))) || abortProcessing)
                    {
                        break;
                    }
                }
                catch (Exception exception)
                {
                    if (((exception is ThreadAbortException) || (exception is StackOverflowException)) || (exception is OutOfMemoryException))
                    {
                        throw;
                    }
                    throw Tracing.ExceptionThrow(method, new InvalidOperationException(Res.GetString("FailedToHandleRequest0"), exception));
                }
            }
            if (abortProcessing)
            {
                return(new NopHandler());
            }
            if (protocol == null)
            {
                if ((request.PathInfo != null) && (request.PathInfo.Length != 0))
                {
                    throw Tracing.ExceptionThrow(method, new InvalidOperationException(Res.GetString("WebUnrecognizedRequestFormatUrl", new object[] { request.PathInfo })));
                }
                throw Tracing.ExceptionThrow(method, new InvalidOperationException(Res.GetString("WebUnrecognizedRequestFormat")));
            }
            if (protocol is UnsupportedRequestProtocol)
            {
                throw Tracing.ExceptionThrow(method, new HttpException(((UnsupportedRequestProtocol)protocol).HttpCode, Res.GetString("WebUnrecognizedRequestFormat")));
            }
            bool isAsync       = protocol.MethodInfo.IsAsync;
            bool enableSession = protocol.MethodAttribute.EnableSession;

            if (isAsync)
            {
                if (enableSession)
                {
                    return(new AsyncSessionHandler(protocol));
                }
                return(new AsyncSessionlessHandler(protocol));
            }
            if (enableSession)
            {
                return(new SyncSessionHandler(protocol));
            }
            return(new SyncSessionlessHandler(protocol));
        }
Beispiel #8
0
        string CreateKey(Type protocolType, Type serverType, bool excludeSchemeHostPort = false, string keySuffix = null)
        {
            //
            // we want to use the hostname to cache since for documentation, WSDL
            // contains the cache hostname, but we definitely don't want to cache the query string!
            //
            string        protocolTypeName = protocolType.FullName;
            string        serverTypeName   = serverType.FullName;
            string        typeHandleString = serverType.TypeHandle.Value.ToString();
            string        url    = excludeSchemeHostPort ? Request.Url.AbsolutePath : Request.Url.GetLeftPart(UriPartial.Path);
            int           length = protocolTypeName.Length + url.Length + serverTypeName.Length + typeHandleString.Length;
            StringBuilder sb     = new StringBuilder(length);

            sb.Append(protocolTypeName);
            sb.Append(url);
            sb.Append(serverTypeName);
            sb.Append(typeHandleString);
            if (keySuffix != null)
            {
                sb.Append(keySuffix);
            }

            CreateCustomKeyForAspNetWebServiceMetadataCache createKey = ServerProtocol.GetCreateCustomKeyForAspNetWebServiceMetadataCacheDelegate(serverType);

            return(createKey(protocolType, serverType, sb.ToString()));
        }
Beispiel #9
0
        internal IHttpHandler CoreGetHandler(Type type, HttpContext context, HttpRequest request, HttpResponse response)
        {
            //Debug.Listeners.Add(new TextWriterTraceListener(response.OutputStream));

            ServerProtocolFactory[] protocolFactories = WebServicesConfiguration.Current.ServerProtocolFactories;
            ServerProtocol          protocol          = null;
            bool abort = false;

            for (int i = 0; i < protocolFactories.Length; i++)
            {
                try {
                    if ((protocol = protocolFactories[i].Create(type, context, request, response, out abort)) != null || abort)
                    {
                        break;
                    }
                }
                catch (Exception e) {
                    throw new InvalidOperationException(Res.GetString(Res.FailedToHandleRequest0), e);
                }
            }

            if (abort)
            {
                return(new NopHandler());
            }

            if (protocol == null)
            {
                throw new InvalidOperationException(Res.GetString(Res.WebUnrecognizedRequestFormat));
            }

            bool isAsync         = protocol.MethodInfo.IsAsync;
            bool requiresSession = protocol.MethodAttribute.EnableSession;

            if (isAsync)
            {
                if (requiresSession)
                {
                    return(new AsyncSessionHandler(protocol));
                }
                else
                {
                    return(new AsyncSessionlessHandler(protocol));
                }
            }
            else
            {
                if (requiresSession)
                {
                    return(new SyncSessionHandler(protocol));
                }
                else
                {
                    return(new SyncSessionlessHandler(protocol));
                }
            }
        }
        internal override void WriteFault(XmlWriter writer, SoapException soapException)
        {
            SoapServerMessage message = ServerProtocol.Message;

            writer.WriteStartDocument();
            writer.WriteStartElement("soap", Soap.Envelope, Soap.Namespace);
            writer.WriteAttributeString("xmlns", "soap", null, Soap.Namespace);
            writer.WriteAttributeString("xmlns", "xsi", null, XmlSchema.InstanceNamespace);
            writer.WriteAttributeString("xmlns", "xsd", null, XmlSchema.Namespace);
            if (ServerProtocol.ServerMethod != null)
            {
                SoapHeaderHandling.WriteHeaders(writer, ServerProtocol.ServerMethod.outHeaderSerializer, message.Headers, ServerProtocol.ServerMethod.outHeaderMappings, SoapHeaderDirection.Fault, ServerProtocol.ServerMethod.use == SoapBindingUse.Encoded, ServerType.serviceNamespace, ServerType.serviceDefaultIsEncoded, Soap.Namespace);
            }
            else
            {
                SoapHeaderHandling.WriteUnknownHeaders(writer, message.Headers, Soap.Namespace);
            }
            writer.WriteStartElement(Soap.Body, Soap.Namespace);

            writer.WriteStartElement(Soap.Fault, Soap.Namespace);
            writer.WriteStartElement(Soap.FaultCode, "");
            XmlQualifiedName code = TranslateFaultCode(soapException.Code);

            if (code.Namespace != null && code.Namespace.Length > 0 && writer.LookupPrefix(code.Namespace) == null)
            {
                writer.WriteAttributeString("xmlns", "q0", null, code.Namespace);
            }
            writer.WriteQualifiedName(code.Name, code.Namespace);
            writer.WriteEndElement();
            writer.WriteElementString(Soap.FaultString, "", ServerProtocol.GenerateFaultString(soapException));
            // Only write an actor element if the actor was specified (it's optional for end-points)
            string actor = soapException.Actor;

            if (actor.Length > 0)
            {
                writer.WriteElementString(Soap.FaultActor, "", actor);
            }

            // Only write a FaultDetail element if exception is related to the body (not a header)
            if (!(soapException is SoapHeaderException))
            {
                if (soapException.Detail == null)
                {
                    writer.WriteStartElement(Soap.FaultDetail, "");
                    writer.WriteEndElement();
                }
                else
                {
                    soapException.Detail.WriteTo(writer);
                }
            }
            writer.WriteEndElement();

            writer.WriteEndElement();
            writer.WriteEndElement();
            writer.Flush();
        }
        internal override void WriteFault(XmlWriter writer, SoapException soapException)
        {
            writer.WriteStartDocument();
            writer.WriteStartElement("soap", Soap.Envelope, Soap12.Namespace);
            writer.WriteAttributeString("xmlns", "soap", null, Soap12.Namespace);
            writer.WriteAttributeString("xmlns", "xsi", null, XmlSchema.InstanceNamespace);
            writer.WriteAttributeString("xmlns", "xsd", null, XmlSchema.Namespace);
            if (ServerProtocol.ServerMethod != null)
            {
                SoapHeaderHandling.WriteHeaders(writer, ServerProtocol.ServerMethod.outHeaderSerializer, ServerProtocol.Message.Headers, ServerProtocol.ServerMethod.outHeaderMappings, SoapHeaderDirection.Fault, ServerProtocol.ServerMethod.use == SoapBindingUse.Encoded, ServerType.serviceNamespace, ServerType.serviceDefaultIsEncoded, Soap12.Namespace);
            }
            else
            {
                SoapHeaderHandling.WriteUnknownHeaders(writer, ServerProtocol.Message.Headers, Soap12.Namespace);
            }

            writer.WriteStartElement(Soap.Body, Soap12.Namespace);

            writer.WriteStartElement(Soap.Fault, Soap12.Namespace);
            writer.WriteStartElement(Soap12.FaultCode, Soap12.Namespace);
            WriteFaultCodeValue(writer, TranslateFaultCode(soapException.Code), soapException.Subcode);
            writer.WriteEndElement(); // </faultcode>
            writer.WriteElementString(Soap12.FaultReason, Soap12.Namespace, ServerProtocol.GenerateFaultString(soapException));
            // Only write an actor element if the actor was specified (it's optional for end-points)
            string actor = soapException.Actor;

            if (actor.Length > 0)
            {
                writer.WriteElementString(Soap12.FaultNode, Soap12.Namespace, actor);
            }

            string role = soapException.Role;

            if (role.Length > 0)
            {
                writer.WriteElementString(Soap12.FaultRole, Soap12.Namespace, role);
            }

            // Only write a FaultDetail element if exception is related to the body (not a header)
            if (!(soapException is SoapHeaderException))
            {
                if (soapException.Detail == null)
                {
                    writer.WriteStartElement(Soap12.FaultDetail, Soap12.Namespace);
                    writer.WriteEndElement();
                }
                else
                {
                    soapException.Detail.WriteTo(writer);
                }
            }
            writer.WriteEndElement();

            writer.WriteEndElement();
            writer.WriteEndElement();
            writer.Flush();
        }
Beispiel #12
0
        internal void NotifyServerCallEnter(ServerProtocol protocol, string stringBuffer)
        {
            try {
                if (NotifySink == null)
                {
                    return;
                }
                StringBuilder methodBuilder = new StringBuilder();
                methodBuilder.Append(protocol.Type.FullName);
                methodBuilder.Append('.');
                methodBuilder.Append(protocol.MethodInfo.Name);
                methodBuilder.Append('(');
                ParameterInfo[] parameterInfos = protocol.MethodInfo.Parameters;
                for (int i = 0; i < parameterInfos.Length; ++i)
                {
                    if (i != 0)
                    {
                        methodBuilder.Append(',');
                    }

                    methodBuilder.Append(parameterInfos[i].ParameterType.FullName);
                }
                methodBuilder.Append(')');

                byte[] buffer = Convert.FromBase64String(stringBuffer);
                CallId callId = new CallId(null, 0, (IntPtr)0, 0, methodBuilder.ToString(), null);

                TraceMethod method = Tracing.On ? new TraceMethod(this, "NotifyServerCallEnter") : null;
                if (Tracing.On)
                {
                    Tracing.Enter("RemoteDebugger", method);
                }

                UnsafeNativeMethods.OnSyncCallEnter(NotifySink, callId, buffer, buffer.Length);

                if (Tracing.On)
                {
                    Tracing.Exit("RemoteDebugger", method);
                }
            }
            catch (Exception e) {
                if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException)
                {
                    throw;
                }
                if (Tracing.On)
                {
                    Tracing.ExceptionCatch(TraceEventType.Warning, typeof(RemoteDebugger), "NotifyServerCallEnter", e);
                }
            }
        }
Beispiel #13
0
 internal void NotifyServerCallEnter(ServerProtocol protocol, string stringBuffer)
 {
     try
     {
         if (this.NotifySink != null)
         {
             StringBuilder builder = new StringBuilder();
             builder.Append(protocol.Type.FullName);
             builder.Append('.');
             builder.Append(protocol.MethodInfo.Name);
             builder.Append('(');
             ParameterInfo[] parameters = protocol.MethodInfo.Parameters;
             for (int i = 0; i < parameters.Length; i++)
             {
                 if (i != 0)
                 {
                     builder.Append(',');
                 }
                 builder.Append(parameters[i].ParameterType.FullName);
             }
             builder.Append(')');
             byte[]      buffer = Convert.FromBase64String(stringBuffer);
             CallId      callId = new CallId(null, 0, IntPtr.Zero, 0L, builder.ToString(), null);
             TraceMethod caller = Tracing.On ? new TraceMethod(this, "NotifyServerCallEnter", new object[0]) : null;
             if (Tracing.On)
             {
                 Tracing.Enter("RemoteDebugger", caller);
             }
             System.Web.Services.UnsafeNativeMethods.OnSyncCallEnter(this.NotifySink, callId, buffer, buffer.Length);
             if (Tracing.On)
             {
                 Tracing.Exit("RemoteDebugger", caller);
             }
         }
     }
     catch (Exception exception)
     {
         if (((exception is ThreadAbortException) || (exception is StackOverflowException)) || (exception is OutOfMemoryException))
         {
             throw;
         }
         if (Tracing.On)
         {
             Tracing.ExceptionCatch(TraceEventType.Warning, typeof(RemoteDebugger), "NotifyServerCallEnter", exception);
         }
     }
 }
        internal override bool WriteException(Exception e, Stream outputStream)
        {
            base.Response.Clear();
            base.Response.ClearHeaders();
            base.Response.ContentType = ContentType.Compose("text/plain", Encoding.UTF8);
            ServerProtocol.SetHttpResponseStatusCode(base.Response, 500);
            base.Response.StatusDescription = HttpWorkerRequest.GetStatusDescription(base.Response.StatusCode);
            StreamWriter writer = new StreamWriter(outputStream, new UTF8Encoding(false));

            if (WebServicesSection.Current.Diagnostics.SuppressReturningExceptions)
            {
                writer.WriteLine(Res.GetString("WebSuppressedExceptionMessage"));
            }
            else
            {
                writer.WriteLine(base.GenerateFaultString(e, true));
            }
            writer.Flush();
            return(true);
        }
        internal static bool IsServerCallInEnabled(ServerProtocol protocol, out string stringBuffer) {
            stringBuffer = null;
            bool enabled = false;
            try {
                if (CompModSwitches.DisableRemoteDebugging.Enabled)
                    return false;

                enabled = protocol.Context.IsDebuggingEnabled && Connection != null;
                if (enabled) {
                    stringBuffer = protocol.Request.Headers[debuggerHeader];
                    enabled = (stringBuffer != null && stringBuffer.Length > 0);
                }
            }
            catch (Exception e) {
                if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException) {
                    throw;
                }
                if (Tracing.On) Tracing.ExceptionCatch(TraceEventType.Warning, typeof(RemoteDebugger), "IsServerCallInEnabled", e);
                enabled = false;
            }
            return enabled;
        }
        internal static bool IsServerCallInEnabled(ServerProtocol protocol, out string stringBuffer)
        {
            stringBuffer = null;
            bool enabled = false;

            try {
                if (CompModSwitches.DisableRemoteDebugging.Enabled)
                {
                    return(false);
                }

                enabled = protocol.Context.IsDebuggingEnabled && Connection != null;
                if (enabled)
                {
                    stringBuffer = protocol.Request.Headers[debuggerHeader];
                    enabled      = (stringBuffer != null && stringBuffer.Length > 0);
                }
            }
            catch (Exception) {
                enabled = false;
            }
            return(enabled);
        }
 internal WebServiceHandler(ServerProtocol protocol)
 {
     this.protocol = protocol;
 }
Beispiel #18
0
 internal AsyncSessionlessHandler(ServerProtocol protocol) : base(protocol)
 {
 }
 internal SyncSessionHandler(ServerProtocol protocol) : base(protocol)
 {
 }
 internal AsyncSessionlessHandler(ServerProtocol protocol) : base(protocol) { }
 internal WebServiceHandler(ServerProtocol protocol) {
     this.protocol = protocol;
 }
        internal void NotifyServerCallEnter(ServerProtocol protocol, string stringBuffer) {
            try {
                if (NotifySink == null) return;
                StringBuilder methodBuilder = new StringBuilder();
                methodBuilder.Append(protocol.Type.FullName);
                methodBuilder.Append('.');
                methodBuilder.Append(protocol.MethodInfo.Name);
                methodBuilder.Append('(');
                ParameterInfo[] parameterInfos = protocol.MethodInfo.Parameters;
                for (int i = 0; i < parameterInfos.Length; ++i) {
                    if (i != 0)
                        methodBuilder.Append(',');

                    methodBuilder.Append(parameterInfos[i].ParameterType.FullName);
                }
                methodBuilder.Append(')');

                byte[] buffer = Convert.FromBase64String(stringBuffer);
                CallId callId = new CallId(null, 0, (IntPtr)0, 0, methodBuilder.ToString(), null);

                TraceMethod method = Tracing.On ? new TraceMethod(this, "NotifyServerCallEnter") : null;
                if (Tracing.On) Tracing.Enter("RemoteDebugger", method);

                UnsafeNativeMethods.OnSyncCallEnter(NotifySink, callId, buffer, buffer.Length);

                if (Tracing.On) Tracing.Exit("RemoteDebugger", method);
            }
            catch (Exception e) {
                if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException) {
                    throw;
                }
                if (Tracing.On) Tracing.ExceptionCatch(TraceEventType.Warning, typeof(RemoteDebugger), "NotifyServerCallEnter", e);
            }
        }
Beispiel #23
0
        internal IHttpHandler CoreGetHandler(Type type, HttpContext context, HttpRequest request, HttpResponse response)
        {
            TraceMethod caller = Tracing.On ? new TraceMethod(this, "CoreGetHandler") : null;

            ServerProtocolFactory[] protocolFactories = GetServerProtocolFactories();
            ServerProtocol          protocol          = null;
            bool abort = false;

            for (int i = 0; i < protocolFactories.Length; i++)
            {
                try {
                    protocol = protocolFactories[i].Create(type, context, request, response, out abort);
                    if ((protocol != null && protocol.GetType() != typeof(UnsupportedRequestProtocol)) || abort)
                    {
                        break;
                    }
                }
                catch (Exception e) {
                    if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException)
                    {
                        throw;
                    }
                    throw Tracing.ExceptionThrow(caller, new InvalidOperationException(Res.GetString(Res.FailedToHandleRequest0), e));
                }
            }

            if (abort)
            {
                return(new NopHandler());
            }

            if (protocol == null)
            {
                if (request.PathInfo != null && request.PathInfo.Length != 0)
                {
                    throw Tracing.ExceptionThrow(caller, new InvalidOperationException(Res.GetString(Res.WebUnrecognizedRequestFormatUrl,
                                                                                                     new object[] { request.PathInfo })));
                }
                else
                {
                    throw Tracing.ExceptionThrow(caller, new InvalidOperationException(Res.GetString(Res.WebUnrecognizedRequestFormat)));
                }
            }
            else if (protocol is UnsupportedRequestProtocol)
            {
                throw Tracing.ExceptionThrow(caller, new HttpException(((UnsupportedRequestProtocol)protocol).HttpCode, Res.GetString(Res.WebUnrecognizedRequestFormat)));
            }

            bool isAsync         = protocol.MethodInfo.IsAsync;
            bool requiresSession = protocol.MethodAttribute.EnableSession;

            if (isAsync)
            {
                if (requiresSession)
                {
                    return(new AsyncSessionHandler(protocol));
                }
                else
                {
                    return(new AsyncSessionlessHandler(protocol));
                }
            }
            else
            {
                if (requiresSession)
                {
                    return(new SyncSessionHandler(protocol));
                }
                else
                {
                    return(new SyncSessionlessHandler(protocol));
                }
            }
        }
 internal static bool IsServerCallInEnabled(ServerProtocol protocol, out string stringBuffer)
 {
     stringBuffer = null;
     bool flag = false;
     try
     {
         if (System.ComponentModel.CompModSwitches.DisableRemoteDebugging.Enabled)
         {
             return false;
         }
         flag = protocol.Context.IsDebuggingEnabled && (Connection != null);
         if (flag)
         {
             stringBuffer = protocol.Request.Headers[debuggerHeader];
             flag = (stringBuffer != null) && (stringBuffer.Length > 0);
         }
     }
     catch (Exception exception)
     {
         if (((exception is ThreadAbortException) || (exception is StackOverflowException)) || (exception is OutOfMemoryException))
         {
             throw;
         }
         if (Tracing.On)
         {
             Tracing.ExceptionCatch(TraceEventType.Warning, typeof(RemoteDebugger), "IsServerCallInEnabled", exception);
         }
         flag = false;
     }
     return flag;
 }
 internal void NotifyServerCallEnter(ServerProtocol protocol, string stringBuffer)
 {
     try
     {
         if (this.NotifySink != null)
         {
             StringBuilder builder = new StringBuilder();
             builder.Append(protocol.Type.FullName);
             builder.Append('.');
             builder.Append(protocol.MethodInfo.Name);
             builder.Append('(');
             ParameterInfo[] parameters = protocol.MethodInfo.Parameters;
             for (int i = 0; i < parameters.Length; i++)
             {
                 if (i != 0)
                 {
                     builder.Append(',');
                 }
                 builder.Append(parameters[i].ParameterType.FullName);
             }
             builder.Append(')');
             byte[] buffer = Convert.FromBase64String(stringBuffer);
             CallId callId = new CallId(null, 0, IntPtr.Zero, 0L, builder.ToString(), null);
             TraceMethod caller = Tracing.On ? new TraceMethod(this, "NotifyServerCallEnter", new object[0]) : null;
             if (Tracing.On)
             {
                 Tracing.Enter("RemoteDebugger", caller);
             }
             System.Web.Services.UnsafeNativeMethods.OnSyncCallEnter(this.NotifySink, callId, buffer, buffer.Length);
             if (Tracing.On)
             {
                 Tracing.Exit("RemoteDebugger", caller);
             }
         }
     }
     catch (Exception exception)
     {
         if (((exception is ThreadAbortException) || (exception is StackOverflowException)) || (exception is OutOfMemoryException))
         {
             throw;
         }
         if (Tracing.On)
         {
             Tracing.ExceptionCatch(TraceEventType.Warning, typeof(RemoteDebugger), "NotifyServerCallEnter", exception);
         }
     }
 }