Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removed unnessecary buffered copy #1029

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/SoapCore/DocumentationWriter/SoapMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions src/SoapCore/MessageEncoder/SoapMessageEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,12 @@ public async Task<Message> 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);
Fixed Show fixed Hide fixed
}

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)
Expand Down
10 changes: 2 additions & 8 deletions src/SoapCore/Meta/BodyWriterExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/SoapCore/SoapCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<Description>SOAP protocol middleware for ASP.NET Core</Description>
<Version>1.1.0.45</Version>
<Version>1.1.0.46</Version>
<Authors>Digital Design</Authors>
<TargetFrameworks>netstandard2.0;netstandard2.1;netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
<PackageId>SoapCore</PackageId>
Expand Down
7 changes: 2 additions & 5 deletions src/SoapCore/SoapEndpointMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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<Message, Task<Message>> MakeProcessorPipe(ISoapMessageProcessor[] soapMessageProcessors, HttpContext httpContext, Func<Message, Task<Message>> processMessageFunc)
Expand Down
Loading