简体   繁体   中英

How to POST a SOAP message on web api (asp.net core ->web api)

I want to post a SOAP XML based message to Web API which i have created in ASP.NET core project template.

Right now i am getting unsupported media type error when i post with with content-type as application/soap+xml.

I know that we should be sending SOAP message to WCF based service but our requirement is like this only. I should be able to consume SOPA message in web API.

Thanks, Sudama

Here is a two-part answer:

Exposing SOAP services with ASP.NET Core:

  • Microsoft is not looking into porting SOAP-capable services in ASP.NET Core , not in a near future (look at this other SO answer which states the same).

  • That being said, nothing is preventing you from using the plain .NET Framework , which supports SOAP either using old ASMX or WCF which are part of .NET Framework 4.5.x at least (with support ending in 2023 ).

  • Lastly, SOAP seems just a technical requirement for you, so you can build a thin SOAP layer just transfering calls to your main ASP.NET Core service.

The only limitation would be to support deploying this on Linux , on which the full .NET Framework does not natively run on; if not, you're good to go.

Consuming SOAP services win ASP.NET Core:

ASP.NET Core supports consuming SOAP Services in ASP.NET Core through the use of WCF Connected services .

I know this was answered however, for future reference, I also implemented a similar solution to Sudama.

I had a requirement for a SOAP message to be consumed that was transmitted from Salesforce, no other options were available so I implemented a SOAP Formatter in .Net Core that transformed the incoming request.

There were a few technical challenges with the read-once stream for the body of the request but if you find it useful I have included a link to the project code below:

https://github.com/TNDStudios/TNDStudios.Salesforce.OutboundReceiver

I resolved this issue by implementing the custom Input & OutPut formatters. These formatters are simple classes they just implement IInputFormatter & IOutPutFormatter supplied by .Net core. Use the context object to read the incoming request and serialize them in the format you want(xml or Json).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM