Giter VIP home page Giter VIP logo

Comments (3)

andersjonsson avatar andersjonsson commented on July 30, 2024 1

Should be fixed in #1033

from soapcore.

andersjonsson avatar andersjonsson commented on July 30, 2024

Yes, that should be a TryParse.
The configured WriteEncoding will be used as a fallback if this method returns null, so there is already logic for that.

With that said it can be necessary to add a custom middleware to set Content-Type anyways.
In my legacy service a few clients sent SOAP1.2 envelopes without Content-Type set and that fails.

I solved that with a regular asp.net middleware (affects performance, but in my case it's much more important to stay backwards compatible than to maximize performance.

const string Soap12NS = "http://www.w3.org/2003/05/soap-envelope";

app.Use(async (context, next) =>
{
	if (context.Request.Method == "POST")
	{
		//This line allows us to set the reader for the request back at the beginning of its stream.
		context.Request.EnableBuffering();

		//We convert the byte[] into a string using UTF8 encoding...
		var bodyAsText = Encoding.UTF8.GetString(await context.Request.Body.ReadFullyAsync());

		try
		{
			var xdoc = XDocument.Parse(bodyAsText);

			bodyAsText = xdoc.ToString();
			context.Request.Body = new MemoryStream(Encoding.UTF8.GetBytes(bodyAsText));

			//Logging!
			await SoapMessageLog.WriteLog(context, bodyAsText);

			//Upgrade Content-Type if Envelope is Soap1.2
			if (context.Request.Headers["Content-Type"] != "application/soap+xml")
			{
				var envelope = xdoc.Descendants().FirstOrDefault(x => x.Name.LocalName == "Envelope");
				if (envelope != null && envelope.Name.ToString().Contains(Soap12NS))
				{
					context.Request.Headers["Content-Type"] = "application/soap+xml";
				}
			}

		}
		catch
		{ }

		//..and finally, assign the read body back to the request body, which is allowed because of EnableRewind()
		context.Request.Body.Position = 0;
	}

	await next();
}

);

from soapcore.

jamespfluger-ava avatar jamespfluger-ava commented on July 30, 2024

Ha, the use case I have is not a standard SoapCore use case, so I did the "dumb" workaround by simply using request.ContentType ?? "application/xm; charset=utf-8" using ReadMessageAsync within SoapMessageEncoder

Appreciate the rapid change!

from soapcore.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.