diff --git a/src/SoapCore/DocumentationWriter/SoapMethods.cs b/src/SoapCore/DocumentationWriter/SoapMethods.cs index 873282c8..c01127dc 100644 --- a/src/SoapCore/DocumentationWriter/SoapMethods.cs +++ b/src/SoapCore/DocumentationWriter/SoapMethods.cs @@ -49,6 +49,15 @@ public static SoapDefinition DeserializeFromString(string xml) return (SoapDefinition)xs.Deserialize(sr); } + public static SoapDefinition DeserializeFromStream(Stream xml) + { + XmlSerializer xs = new XmlSerializer(typeof(SoapDefinition)); + + xs.UnknownElement += _unknownElementHandler; + + return (SoapDefinition)xs.Deserialize(xml); + } + public string GenerateDocumentation() { #if NETCOREAPP3_1_OR_GREATER diff --git a/src/SoapCore/MessageEncoder/SoapMessageEncoder.cs b/src/SoapCore/MessageEncoder/SoapMessageEncoder.cs index 5e4951b6..5b53ee68 100644 --- a/src/SoapCore/MessageEncoder/SoapMessageEncoder.cs +++ b/src/SoapCore/MessageEncoder/SoapMessageEncoder.cs @@ -159,13 +159,12 @@ public async Task ReadMessageAsync(Stream stream, int maxSizeOfHeaders, else { var streamReaderWithEncoding = new StreamReader(ms, readEncoding); - var xmlReaderSettings = new XmlReaderSettings() { IgnoreWhitespace = true, DtdProcessing = DtdProcessing.Prohibit, CloseInput = true }; + + var xmlReaderSettings = new XmlReaderSettings() { XmlResolver = null, IgnoreWhitespace = true, DtdProcessing = DtdProcessing.Prohibit, CloseInput = true }; reader = XmlReader.Create(streamReaderWithEncoding, xmlReaderSettings); } - var message = Message.CreateMessage(reader, maxSizeOfHeaders, MessageVersion).CreateBufferedCopy(int.MaxValue).CreateMessage(); - - return message; + return Message.CreateMessage(reader, maxSizeOfHeaders, MessageVersion); } public virtual async Task WriteMessageAsync(Message message, HttpContext httpContext, PipeWriter pipeWriter, bool indentXml) diff --git a/src/SoapCore/Meta/BodyWriterExtensions.cs b/src/SoapCore/Meta/BodyWriterExtensions.cs index b7a39b5c..b937a340 100644 --- a/src/SoapCore/Meta/BodyWriterExtensions.cs +++ b/src/SoapCore/Meta/BodyWriterExtensions.cs @@ -40,11 +40,8 @@ public static bool TryAddSchemaTypeFromXmlSchemaProviderAttribute(this XmlDictio memoryStream.Position = 0; - var streamReader = new StreamReader(memoryStream); - var result = streamReader.ReadToEnd(); - var doc = new XmlDocument(); - doc.LoadXml(result); + doc.Load(memoryStream); doc.DocumentElement.WriteContentTo(writer); return true; @@ -130,11 +127,8 @@ public static bool TryAddSchemaTypeFromXmlSchemaProviderAttribute(this XmlDictio schema.Write(memoryStream); memoryStream.Position = 0; - var streamReader = new StreamReader(memoryStream); - var result = streamReader.ReadToEnd(); - var doc = new XmlDocument(); - doc.LoadXml(result); + doc.Load(memoryStream); doc.DocumentElement.WriteContentTo(writer); return true; diff --git a/src/SoapCore/SoapCore.csproj b/src/SoapCore/SoapCore.csproj index 4c81d8d5..f2d01ab6 100644 --- a/src/SoapCore/SoapCore.csproj +++ b/src/SoapCore/SoapCore.csproj @@ -2,7 +2,7 @@ SOAP protocol middleware for ASP.NET Core - 1.1.0.45 + 1.1.0.46 Digital Design netstandard2.0;netstandard2.1;netcoreapp3.1;net5.0;net6.0 SoapCore diff --git a/src/SoapCore/SoapEndpointMiddleware.cs b/src/SoapCore/SoapEndpointMiddleware.cs index b3e2ca2d..4b9421d5 100644 --- a/src/SoapCore/SoapEndpointMiddleware.cs +++ b/src/SoapCore/SoapEndpointMiddleware.cs @@ -264,10 +264,7 @@ private async Task ProcessMeta(HttpContext httpContext, bool showDocumentation) var ms = new MemoryStream(); await messageEncoder.WriteMessageAsync(responseMessage, httpContext, ms, _options.IndentWsdl); ms.Position = 0; - using var sr = new StreamReader(ms); - var wsdl = await sr.ReadToEndAsync(); - - var documentation = SoapDefinition.DeserializeFromString(wsdl).GenerateDocumentation(); + var documentation = SoapDefinition.DeserializeFromStream(ms).GenerateDocumentation(); await httpContext.Response.WriteAsync(documentation); @@ -438,7 +435,7 @@ bool TryGetRequestValue(string key, out StringValues value) bodyWriter.WriteBodyContents(dictionaryWriter); dictionaryWriter.Flush(); - await context.Response.WriteAsync(DefaultEncodings.UTF8.GetString(ms.ToArray())); + await ms.CopyToAsync(context.Response.Body); } private Func> MakeProcessorPipe(ISoapMessageProcessor[] soapMessageProcessors, HttpContext httpContext, Func> processMessageFunc)