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?

3
  • Does this answer your question? How to return raw string with ApiController? Commented Dec 12, 2019 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. Commented Dec 12, 2019 at 14:22
  • i have been testing with postman, after using Igor's answer, postman displayed the correct result. Commented Dec 12, 2019 at 14:25

1 Answer 1

1
return this.Content(response, "text/xml");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.