Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Receiving content type xml through API #1528


User avatar
0
brallierc created

We are using a service that sends data back to our API but they can only send XML. Our API returns Invalid Content Type. How can I setup the API to accept text/xml?


3 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Abp removes all web api formatters expect Json formatter by default. You can override PostInitialize of your WebApi module and add a xml formatter.

    Define a xml formatter like below,

    public class CustomXmlFormatter : XmlMediaTypeFormatter
    {
        public ZeroXmlFormatter()
        {
            UseXmlSerializer = true;
        }
    }
    
    public override void PostInitialize()
    {
        base.PostInitialize();
        
        Configuration.Modules.AbpWebApi().HttpConfiguration.Formatters.Add(
            new CustomXmlFormatter()
        );
    }
    
  • User Avatar
    0
    mihalicz created

    This only works for WebApi controllers. How can I make this work for Dynamic Controllers? For example, application/json is the only option that shows in Swagger but I want the option to send XML straight to the application layer through Swagger

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    I think this is not possible right now. We have an issue regarding to this problem here <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/issues/301">https://github.com/aspnetboilerplate/as ... issues/301</a>.

    If you can write a comment on this issue, we will give a higher priority to this problem.

    Thanks.