Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return XML as HTTP response

Tags:

http

xml

asp.net

I've been given a seemingly simple task.

When a given URL is requested the response should simply be some valid XML.

How do I achieve this?

The URL will contain all the necessary code behind to get the data and construct the correct XML string. How do you then go ahead and manipulate the response to return this string only? The caller is receiving the XML string and populating a database with it, that's there responsibility I just need to provide this part of the project.

Thanks

like image 993
Robert Avatar asked Sep 08 '09 10:09

Robert


3 Answers

Take a look at this :

Response.Clear();
Response.Write(yourXml);
Response.ContentType = "text/xml";
Response.End();
like image 53
Canavar Avatar answered Sep 28 '22 05:09

Canavar


I would go for an HttpHandler. This way you circumvent all asp.net control creation etc. which is better for performance and seeing as you will not be outputting any html there's no point in using an actual aspx page.

like image 28
Colin Avatar answered Sep 28 '22 03:09

Colin


Assuming you have your XML string created you can clear the response and just write your string out.

Response.Clear();
Response.ContentType = "text/xml";
Response.Write(myXMLString);
like image 33
Geoff Avatar answered Sep 28 '22 05:09

Geoff