How do I setup a scenario where one website hosted at X publishes a URL that when browsed to will return purely XML.
A web page elsewhere is going to hit this URL, load the XML into objects.
So I want a url like http://www.xml.com/document.aspx?id=1
Another site will use webresponse and webrequest objects to get the response from the above page, I want the response to be good XML so I can just use the XML to populate objects.
I did get something working but the response contained all the HTML required to render the page and I actually just want XML as the response.
Probably the best way to this is with a HttpHandler/ASHX file, but if you want to do it with a page it's perfectly possible. The two key points are:
Response.ContentType = "text/xml"
How you generate the XML itself is up to you, but if the XML represents an object graph, you can use an
XmlSerializer
(from theSystem.Xml.Serialization
namespace) to write the XML directly to the Response stream for you e.g.If you already have the XML, then once you've set the ContentType, you just need to write it to the Response stream and then end and flush the stream.