How to return XML in ASP.NET?

前端 未结 9 1430
粉色の甜心
粉色の甜心 2020-11-28 20:17

I have encountered many half-solutions to the task of returning XML in ASP.NET. I don\'t want to blindly copy & paste some code that happens to work most of the time, th

9条回答
  •  萌比男神i
    2020-11-28 20:18

    Below is the server side code that would call the handler and recieve the stream data and loads into xml doc

     Stream stream = null;
           **Create a web request with the specified URL**
            WebRequest myWebRequest = WebRequest.Create(@"http://localhost/XMLProvider/XMLProcessorHandler.ashx");
            **Senda a web request and wait for response.**
            WebResponse webResponse = myWebRequest.GetResponse();
            **Get the stream object from response object**
            stream = webResponse.GetResponseStream();
    
           XmlDocument xmlDoc = new XmlDocument();
          **Load stream data into xml**
           xmlDoc.Load(stream);
    

提交回复
热议问题