internal void SetStream(System.IO.Stream stream) { if (this.extensionStream != null) { this.extensionStream.SetInnerStream(stream); this.extensionStream.SetStreamReady(); this.extensionStream = null; } else { this.stream = stream; } }
internal void SetStream(Stream stream) { if (extensionStream != null) { extensionStream.SetInnerStream(stream); extensionStream.SetStreamReady(); // The extension stream should now be referenced by either this.stream // or an extension that has chained it to another stream. extensionStream = null; } else { this.stream = stream; } }
internal override bool WriteException(Exception e, Stream outputStream) { if (message == null) return false; message.Headers.Clear(); if (serverMethod != null && this.Target != null) SoapHeaderHandling.GetHeaderMembers(message.Headers, this.Target, serverMethod.outHeaderMappings, SoapHeaderDirection.Fault, false); SoapException soapException; if (e is SoapException) soapException = (SoapException)e; else if (serverMethod != null && serverMethod.rpc && helper.Version == SoapProtocolVersion.Soap12 && e is ArgumentException) // special case to handle soap 1.2 rpc "BadArguments" fault soapException = SoapException.Create(Version, Res.GetString(Res.WebRequestUnableToProcess), new XmlQualifiedName(Soap.Code.Client, Soap.Namespace), null, null, null, new SoapFaultSubCode(Soap12FaultCodes.RpcBadArgumentsFaultCode), e); else soapException = SoapException.Create(Version, Res.GetString(Res.WebRequestUnableToProcess), new XmlQualifiedName(Soap.Code.Server, Soap.Namespace), e); if (SoapException.IsVersionMismatchFaultCode(soapException.Code)) { if (IsSupported(WebServiceProtocols.HttpSoap12)) { SoapUnknownHeader unknownHeader = CreateUpgradeHeader(); if (unknownHeader != null) Message.Headers.Add(unknownHeader); } } Response.ClearHeaders(); Response.Clear(); HttpStatusCode statusCode = helper.SetResponseErrorCode(Response, soapException); bool disableExtensions = false; SoapExtensionStream extensionStream = new SoapExtensionStream(); if (message.allExtensions != null) message.SetExtensionStream(extensionStream); try { message.InitExtensionStreamChain(message.allExtensions); } catch (Exception ex) { if (ex is ThreadAbortException || ex is StackOverflowException || ex is OutOfMemoryException) { throw; } if (Tracing.On) Tracing.ExceptionCatch(TraceEventType.Warning, this, "WriteException", ex); disableExtensions = true; } message.SetStage(SoapMessageStage.BeforeSerialize); message.ContentType = ContentType.Compose(helper.HttpContentType, Encoding.UTF8); message.Exception = soapException; if (!disableExtensions) { try { message.RunExtensions(message.allExtensions, false); } catch (Exception ex) { if (ex is ThreadAbortException || ex is StackOverflowException || ex is OutOfMemoryException) { throw; } if (Tracing.On) Tracing.ExceptionCatch(TraceEventType.Warning, this, "WriteException", ex); disableExtensions = true; } } message.SetStream(outputStream); Response.ContentType = message.ContentType; if (message.ContentEncoding != null && message.ContentEncoding.Length > 0) { Response.AppendHeader(ContentType.ContentEncoding, message.ContentEncoding); } XmlWriter writer = GetWriterForMessage(message, 512); if (writer == null) throw new InvalidOperationException(Res.GetString(Res.WebNullWriterForMessage)); helper.WriteFault(writer, message.Exception, statusCode); if (!disableExtensions) { SoapException extensionException = null; try { message.SetStage(SoapMessageStage.AfterSerialize); message.RunExtensions(message.allExtensions, false); } catch (Exception ex) { if (ex is ThreadAbortException || ex is StackOverflowException || ex is OutOfMemoryException) { throw; } if (Tracing.On) Tracing.ExceptionCatch(TraceEventType.Warning, this, "WriteException", ex); if (!extensionStream.HasWritten) { // if we haven't already written to the stream, we may be able to send an error extensionException = SoapException.Create(Version, Res.GetString(Res.WebExtensionError), new XmlQualifiedName(Soap.Code.Server, Soap.Namespace), ex); } } if (extensionException != null) { Response.ContentType = ContentType.Compose(ContentType.TextPlain, Encoding.UTF8); StreamWriter sw = new StreamWriter(outputStream, new UTF8Encoding(false)); sw.WriteLine(GenerateFaultString(message.Exception)); sw.Flush(); } } return true; }
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); }
internal void SetExtensionStream(SoapExtensionStream extensionStream) { this.extensionStream = extensionStream; this.stream = extensionStream; }
internal void SetStream(Stream stream) { if (extensionStream != null) { extensionStream.SetInnerStream(stream); extensionStream.SetStreamReady(); // The extension stream should now be referenced by either this.stream // or an extension that has chained it to another stream. extensionStream = null; } else this.stream = stream; }
internal void SetStream(Stream stream) { if (this.extensionStream != null) { this.extensionStream.SetInnerStream(stream); this.extensionStream.SetStreamReady(); this.extensionStream = (SoapExtensionStream) null; } else this.stream = stream; }