0

I'm trying to return the following xml from a web api

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE cXML SYSTEM "http://xml.cxml.org/schemas/cXML/1.2.014/cXML.dtd">
<cXML payloadID="payloadID" xml:lang="en" timestamp="2019-12-12T12:57:27-08:00">
  <Response>
    <Status code="200" text="OK" />
  </Response>
</cXML>

but the actual return is

<cXML payloadID="payloadID" xml:lang="en" timestamp="2019-12-12T12:57:27-08:00">
<Response>
<Status code="200" text="OK" />
</Response>
</cXML>

here's a code snippet

[HttpPost("api/[controller]/{format}"), FormatFilter]
    public IActionResult Post([FromBody] AribaPurchaseOrder.Order Order)
    {
        // Process Order .......

        //Ariba order response
        var response = "";
        response += @"<?xml version=""1.0"" encoding=""UTF-8""?>";
        response += @"<!DOCTYPE cXML SYSTEM ""http://xml.cxml.org/schemas/cXML/1.2.014/cXML.dtd"">";

        response += $@"<cXML payloadID=""{Order.PayloadID}"" xml:lang=""en"" timestamp=""{GetAribaFormatTimeStamp()}"">";
        response += @"<Response>";
        response += @"<Status code=""200"" text=""OK""/>";
        response += @"</Response>";
        response += @"</cXML>";

        return new ObjectResult(response) { StatusCode = 200 };
    }

Can anyone advise how to send the response in the correct format?

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
JohnL
  • 99
  • 3
  • 12
  • Does this answer your question? [How to return raw string with ApiController?](https://stackoverflow.com/questions/14046417/how-to-return-raw-string-with-apicontroller) – Heretic Monkey Dec 12 '19 at 14:18
  • How are you reading the response. The missing line may be sent put the viewer may not be displaying the missing lines. – jdweng Dec 12 '19 at 14:22
  • i have been testing with postman, after using Igor's answer, postman displayed the correct result. – JohnL Dec 12 '19 at 14:25

1 Answers1

1
return this.Content(response, "text/xml");
Igor Buchelnikov
  • 505
  • 4
  • 14