0

I am writing the c# component of a .aspx page which an external site will be sending XML to. My page needs to be able to receive the XML and parse it, but I am getting hung up on receiving the XML.

My page is getting hit with the XML page, but Request.Files.Count==0 and Request.InputStream.Length==0, even though I know that both of these statements should be false because the page is logging the reception of the file and HttpContext.Current != null. I am using the following code:

    Stream stream = HttpContext.Current.Request.InputStream;
    stream.Position = 0;
    XmlTextReader reader = new XmlTextReader(stream);

    log("" + Request.Files.Count, tw);
    log("Does the current request exist?",tw);
    log(HttpContext.Current != null ? "Yes" : "No",tw);
    log("XML Retrieved!", tw);
    log("Byte Length of " + stream.Length, tw);

My log.txt file has the following output:

    0
    Does the current request exist?
    Yes
    XML Retrieved!
    Byte Length of 0
  • can you elaborate on "the page is logging the reception of the file" – Robert Levy Jul 03 '12 at 15:35
  • Sure, I have a method that creates a log.txt file every time that it receives the XML. When I trigger the XML to send from the external site, log.txt is created, so the XML is definitely getting there. – Brent Baumgartner Jul 03 '12 at 15:39
  • A few questions: How is the data sent from the other server? Directly posting XML over http? Posting a form from browser with Xml in a field, and the Xml was data fetched from other server? Also, on your end is it an aspx page or a http handler (ashx file) that receives the request? – user1429080 Jul 03 '12 at 17:21
  • It's sent by directly posting XML over http, or at least I assume so. The site gives a callback url to "Where we post when your export is complete" and an example of the XML that will be sent: ` http://example.com/exports/1234.csv 17 daily ` – Brent Baumgartner Jul 03 '12 at 17:23

1 Answers1

0

Issue Solved, in this case I needed to reference Page.Request.InputStream instead of HttpContext.Current.Request.InputStream.

My code for receiving the XML and reading it into a String:

    Page.Response.ContentType = "text/xml";
    StreamReader sr = new StreamReader(Page.Request.InputStream);
    String main = Server.UrlDecode(sr.ReadToEnd());