views:

28

answers:

2

I am trying to pass through some XML from an external website.

What is the best way of doing this, through c# webpage or asp.MVC?

A: 

Either should be fine. MVC is probably easiest (in terms of getting a raw response), but you could do the same in regular ASP.NET just by using a handler (possibly .ashx), or just by clearing the response.

Marc Gravell
+1  A: 

I tend to use something like this for working with external XML documents / RSS feeds etc:

string sURL = ".....";
// Create a request for the URL. 
WebRequest oRequest = WebRequest.Create(sUrl);
// Get the response.
WebResponse oResponse = oRequest.GetResponse();
// Get the stream containing content returned by the server.
Stream oDataStream = oResponse.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader oReader = new StreamReader(oDataStream, System.Text.Encoding.Default);
// Read the content.
string sXML = oReader.ReadToEnd();
// Convert string to XML
XDocument oFeed = XDocument.Parse(sXML);
TimS
var myWebClient = new WebClient();var stream = myWebClient.OpenRead("URL");if (stream != null){var streamReader = new StreamReader(stream);var textXml = streamReader.ReadToEnd(); this.Response.Clear(); this.Response.ClearContent(); this.Response.ClearHeaders(); this.Response.Buffer = true; this.Response.BufferOutput = true; this.Response.ContentType = "text/xml"; this.Response.Write(textXml); } Response.Flush(); Response.End();
Coppermill
Yes, got it, thanks, code above
Coppermill