예제 #1
0
        internal override bool WriteException(Exception e, Stream outputStream)
        {
            SoapException exception;

            if (this.message == null)
            {
                return(false);
            }
            this.message.Headers.Clear();
            if ((this.serverMethod != null) && (this.Target != null))
            {
                SoapHeaderHandling.GetHeaderMembers(this.message.Headers, this.Target, this.serverMethod.outHeaderMappings, SoapHeaderDirection.Fault, false);
            }
            if (e is SoapException)
            {
                exception = (SoapException)e;
            }
            else if (((this.serverMethod != null) && this.serverMethod.rpc) && ((this.helper.Version == SoapProtocolVersion.Soap12) && (e is ArgumentException)))
            {
                exception = SoapException.Create(this.Version, System.Web.Services.Res.GetString("WebRequestUnableToProcess"), new XmlQualifiedName("Client", "http://schemas.xmlsoap.org/soap/envelope/"), null, null, null, new SoapFaultSubCode(Soap12FaultCodes.RpcBadArgumentsFaultCode), e);
            }
            else
            {
                exception = SoapException.Create(this.Version, System.Web.Services.Res.GetString("WebRequestUnableToProcess"), new XmlQualifiedName("Server", "http://schemas.xmlsoap.org/soap/envelope/"), e);
            }
            if (SoapException.IsVersionMismatchFaultCode(exception.Code) && this.IsSupported(WebServiceProtocols.HttpSoap12))
            {
                SoapUnknownHeader header = this.CreateUpgradeHeader();
                if (header != null)
                {
                    this.Message.Headers.Add(header);
                }
            }
            base.Response.ClearHeaders();
            base.Response.Clear();
            HttpStatusCode      statusCode      = this.helper.SetResponseErrorCode(base.Response, exception);
            bool                flag            = false;
            SoapExtensionStream extensionStream = new SoapExtensionStream();

            if (this.message.allExtensions != null)
            {
                this.message.SetExtensionStream(extensionStream);
            }
            try
            {
                this.message.InitExtensionStreamChain(this.message.allExtensions);
            }
            catch (Exception exception2)
            {
                if (((exception2 is ThreadAbortException) || (exception2 is StackOverflowException)) || (exception2 is OutOfMemoryException))
                {
                    throw;
                }
                if (Tracing.On)
                {
                    Tracing.ExceptionCatch(TraceEventType.Warning, this, "WriteException", exception2);
                }
                flag = true;
            }
            this.message.SetStage(SoapMessageStage.BeforeSerialize);
            this.message.ContentType = ContentType.Compose(this.helper.HttpContentType, Encoding.UTF8);
            this.message.Exception   = exception;
            if (!flag)
            {
                try
                {
                    this.message.RunExtensions(this.message.allExtensions, false);
                }
                catch (Exception exception3)
                {
                    if (((exception3 is ThreadAbortException) || (exception3 is StackOverflowException)) || (exception3 is OutOfMemoryException))
                    {
                        throw;
                    }
                    if (Tracing.On)
                    {
                        Tracing.ExceptionCatch(TraceEventType.Warning, this, "WriteException", exception3);
                    }
                    flag = true;
                }
            }
            this.message.SetStream(outputStream);
            base.Response.ContentType = this.message.ContentType;
            if ((this.message.ContentEncoding != null) && (this.message.ContentEncoding.Length > 0))
            {
                base.Response.AppendHeader("Content-Encoding", this.message.ContentEncoding);
            }
            XmlWriter writerForMessage = this.GetWriterForMessage(this.message, 0x200);

            if (writerForMessage == null)
            {
                throw new InvalidOperationException(System.Web.Services.Res.GetString("WebNullWriterForMessage"));
            }
            this.helper.WriteFault(writerForMessage, this.message.Exception, statusCode);
            if (!flag)
            {
                SoapException exception4 = null;
                try
                {
                    this.message.SetStage(SoapMessageStage.AfterSerialize);
                    this.message.RunExtensions(this.message.allExtensions, false);
                }
                catch (Exception exception5)
                {
                    if (((exception5 is ThreadAbortException) || (exception5 is StackOverflowException)) || (exception5 is OutOfMemoryException))
                    {
                        throw;
                    }
                    if (Tracing.On)
                    {
                        Tracing.ExceptionCatch(TraceEventType.Warning, this, "WriteException", exception5);
                    }
                    if (!extensionStream.HasWritten)
                    {
                        exception4 = SoapException.Create(this.Version, System.Web.Services.Res.GetString("WebExtensionError"), new XmlQualifiedName("Server", "http://schemas.xmlsoap.org/soap/envelope/"), exception5);
                    }
                }
                if (exception4 != null)
                {
                    base.Response.ContentType = ContentType.Compose("text/plain", Encoding.UTF8);
                    StreamWriter writer2 = new StreamWriter(outputStream, new UTF8Encoding(false));
                    writer2.WriteLine(base.GenerateFaultString(this.message.Exception));
                    writer2.Flush();
                }
            }
            return(true);
        }
예제 #2
0
        internal override bool Initialize()
        {
            this.GuessVersion();
            this.message             = new SoapServerMessage(this);
            this.onewayInitException = null;
            this.serverType          = (SoapServerType)base.GetFromCache(typeof(SoapServerProtocol), base.Type);
            if (this.serverType == null)
            {
                lock (ServerProtocol.InternalSyncObject)
                {
                    this.serverType = (SoapServerType)base.GetFromCache(typeof(SoapServerProtocol), base.Type);
                    if (this.serverType == null)
                    {
                        this.serverType = new SoapServerType(base.Type, this.protocolsSupported);
                        base.AddToCache(typeof(SoapServerProtocol), base.Type, this.serverType);
                    }
                }
            }
            Exception innerException = null;

            try
            {
                this.message.highPriConfigExtensions = SoapMessage.InitializeExtensions(this.serverType.HighPriExtensions, this.serverType.HighPriExtensionInitializers);
                this.message.highPriConfigExtensions = this.ModifyInitializedExtensions(PriorityGroup.High, this.message.highPriConfigExtensions);
                this.message.SetStream(base.Request.InputStream);
                this.message.InitExtensionStreamChain(this.message.highPriConfigExtensions);
                this.message.SetStage(SoapMessageStage.BeforeDeserialize);
                this.message.ContentType     = base.Request.ContentType;
                this.message.ContentEncoding = base.Request.Headers["Content-Encoding"];
                this.message.RunExtensions(this.message.highPriConfigExtensions, false);
                innerException = this.message.Exception;
            }
            catch (Exception exception2)
            {
                if (((exception2 is ThreadAbortException) || (exception2 is StackOverflowException)) || (exception2 is OutOfMemoryException))
                {
                    throw;
                }
                if (Tracing.On)
                {
                    Tracing.ExceptionCatch(TraceEventType.Warning, this, "Initialize", exception2);
                }
                innerException = exception2;
            }
            this.message.allExtensions = this.message.highPriConfigExtensions;
            this.GuessVersion();
            try
            {
                this.serverMethod = this.RouteRequest(this.message);
                if (this.serverMethod == null)
                {
                    throw new SoapException(System.Web.Services.Res.GetString("UnableToHandleRequest0"), new XmlQualifiedName("Server", "http://schemas.xmlsoap.org/soap/envelope/"));
                }
            }
            catch (Exception exception3)
            {
                if (((exception3 is ThreadAbortException) || (exception3 is StackOverflowException)) || (exception3 is OutOfMemoryException))
                {
                    throw;
                }
                if (this.helper.RequestNamespace != null)
                {
                    this.SetHelper(SoapServerProtocolHelper.GetHelper(this, this.helper.RequestNamespace));
                }
                this.CheckHelperVersion();
                throw;
            }
            this.isOneWay = this.serverMethod.oneWay;
            if (innerException == null)
            {
                try
                {
                    SoapReflectedExtension[] reflectedExtensions = (SoapReflectedExtension[])CombineExtensionsHelper(this.serverMethod.extensions, this.serverType.LowPriExtensions, typeof(SoapReflectedExtension));
                    object[] extensionInitializers = (object[])CombineExtensionsHelper(this.serverMethod.extensionInitializers, this.serverType.LowPriExtensionInitializers, typeof(object));
                    this.message.otherExtensions = SoapMessage.InitializeExtensions(reflectedExtensions, extensionInitializers);
                    this.message.otherExtensions = this.ModifyInitializedExtensions(PriorityGroup.Low, this.message.otherExtensions);
                    this.message.allExtensions   = (SoapExtension[])CombineExtensionsHelper(this.message.highPriConfigExtensions, this.message.otherExtensions, typeof(SoapExtension));
                }
                catch (Exception exception4)
                {
                    if (((exception4 is ThreadAbortException) || (exception4 is StackOverflowException)) || (exception4 is OutOfMemoryException))
                    {
                        throw;
                    }
                    if (Tracing.On)
                    {
                        Tracing.ExceptionCatch(TraceEventType.Warning, this, "Initialize", exception4);
                    }
                    innerException = exception4;
                }
            }
            if (innerException != null)
            {
                if (!this.isOneWay)
                {
                    if (innerException is SoapException)
                    {
                        throw innerException;
                    }
                    throw SoapException.Create(this.Version, System.Web.Services.Res.GetString("WebConfigExtensionError"), new XmlQualifiedName("Server", "http://schemas.xmlsoap.org/soap/envelope/"), innerException);
                }
                this.onewayInitException = innerException;
            }
            return(true);
        }