XML POST and Analysis in ASP.NET

If someone sends XML from an application to my ASP.NET page, how can I parse it and return an XML response?

Example client code sending XML to my URL:

WebRequest req = null; WebResponse rsp = null; string uri = "https://beta.abc.company.com/mypage.aspx"; req = WebRequest.Create(uri); req.Method = "POST"; req.ContentType = "text/xml"; StreamWriter writer = new StreamWriter(req.GetRequestStream()); writer.WriteLine(txtXML.Text.ToString()); writer.Close(); rsp = req.GetResponse(); 

How can I parse XML from mypage.aspx and give an answer as XML?

+4
source share
1 answer

You can read the XML from the request stream. Therefore, inside mypage.aspx :

 protected void Page_Load(object sender, EventAgrs e) { using (var reader = new StreamReader(Request.InputStream)) { string xml = reader.ReadToEnd(); // do something with the XML } } 
+5
source

All Articles