In SoapCore the HttpContext
is replaced with a MemoryStream
which is the snippet contained below, or can be found on GitHub.
// `HttpContext.Request.Body` comes in as a `FileBufferingReadStream`
private async Task ProcessOperation(HttpContext httpContext, IServiceProvider serviceProvider)
{
Message responseMessage;
//Reload the body to ensure we have the full message
var memoryStream = new MemoryStream((int)httpContext.Request.ContentLength.GetValueOrDefault(1024));
await httpContext.Request.Body.CopyToAsync(memoryStream).ConfigureAwait(false);
memoryStream.Seek(0, SeekOrigin.Begin);
httpContext.Request.Body = memoryStream;
// ... Removed for brevity
}
I can't figure out how to convert the body into a string
so I can use XPath to get some descendants:
using var reader = new StreamReader(httpContext.Request.Body);
// The `requestBody` is cutoff and appears to only be half of the request, which
// appears to be the issue
var requestBody = await reader.ReadToEndAsync();
// Throws on this line with `XmlException There are multiple root elements`, which
// based on the requestBody being clipped makes sense
var xDocument = XDocument.Parse(requestBody);
var query = $"//{prefix}:{bodyElement}";
return xDocument.XPathSelectElement(query, GetXmlNamespaceManager(prefix, uri));
Can anyone see why this doesn't work, or uses SoapCore to get the raw request body as a string
instead of deserializing to models?