Solved

Read XML request in ASP.NET

Posted on 2007-03-19
15
647 Views
Last Modified: 2008-02-01
I'm trying to port an ajax app from ASP to ASP.NET (not sure if its 2.0, or how to tell). I have an [index.asp] page that makes ajax calls to [process.asp] page.   I use this code to grab the background xml requests arriving at [process.asp]  :
------------------------------------------------------------
Set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load(request)
------------------------------------------------------------

How do i do the same thing for ASP.NET ? ...  here's an example xml string that's sent :

-------------------------------------
<?xml version="1.0"?>
<user task="userLookup">
<queryString>SELECT firstName FROM users</queryString>
</user>
-------------------------------------

Please help !
0
Comment
Question by:Gitcho
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
15 Comments
 
LVL 23

Expert Comment

by:Christopher Kile
ID: 18750376
You can use virtually the same code if you create an Interop assembly that wraps the COM object you're using.  I don't necessarily recommend that, but without knowing all the functionality you might be using, I don't really know where to direct you in the .NET CLR functions for XML management.
0
 
LVL 5

Author Comment

by:Gitcho
ID: 18750895
thx, but I'd prefer the syntax for reading an XML request in ASP.net ...  
0
 
LVL 23

Expert Comment

by:Christopher Kile
ID: 18751244
Well, just to be clear, it is not a case of "what is the syntax" but "what libraries are we using, what functions are you calling, and what parameters do they expect".  

With that in mind, I have never worked with the XMLDOM control before and do not know exactly what parameters IT expects.  For instance, in the statement

xmlDoc.load(request)

what type of argument is request?

Regardless of my own questions, I believe the information in the following two links will be very helpful to you:

http://msdn2.microsoft.com/en-us/library/hf9hbf87(VS.80).aspx
http://msdn2.microsoft.com/en-us/library/system.xml.xmldocument(VS.80).aspx


0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 5

Author Comment

by:Gitcho
ID: 18761023
sorry cpkilekofp ... that doesn't help ... i'm familiar with those links (XMLDOM overview).  What I need is the syntax for reading XML data posted to an ASP.NET page.  I provided an example of what type the "request" object is in my original question (the XML string), but "xmlDoc.load(request)" is classic ASP syntax, and not what I'm looking for.
0
 
LVL 23

Expert Comment

by:Christopher Kile
ID: 18764578
OK...you have a response coming from a URL from which you have requested XML information, and you want to load it as XML...I think I understand you now, the "request" thing threw me.

When you say "AJAX calls", what object is mediating the request?  I have no idea what this looks like in ASP, but in ASP.NET my assumption is that you're using some descendant of WebRequest.  You'll tell the WebRequest to GetResponse, which will return a WebResponse.  The body of the response is returned as a Stream by GetResponseStream.  It is this body that will contain your XML. SO....

Dim xmlDoc as New System.XML
Dim urlString as String = <whatever URL the XML is being provided by>

xmlDoc.Load(System.WebRequest.Create(urlString).GetResponse().GetResponseStream())

...should be the code to get that XML and load it into an XML document.
0
 
LVL 5

Author Comment

by:Gitcho
ID: 18801502
i get this error :

Compiler Error Message: BC30182: Type expected.
0
 
LVL 5

Author Comment

by:Gitcho
ID: 18801508
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30182: Type expected.

Source Error:


Line 1:  <%
Line 2:  Dim xmlDoc as New System.XML
Line 3:  Dim urlString as String = "<whatever URL the XML is being provided by>"
Line 4:  
 
0
 
LVL 5

Author Comment

by:Gitcho
ID: 18801510
error is on line 2
0
 
LVL 23

Expert Comment

by:Christopher Kile
ID: 18802277
Ouch, sorry.

Dim xmlDoc as New System.XML

should be

Dim xmlDoc as New System.Xml.XmlDocument
0
 
LVL 5

Author Comment

by:Gitcho
ID: 18803122
I think you're a bit confused ... the XML is arriving at the page as POST, not being retrieved by the page ... the receiving aspx page is simply a processor that returns more xml ...


This is the code I use on the receiving ASP page :

Set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load(request)

This is the javascript code that sends :

function sendXML(sData,querystring,resultHandlerFunction,targetPage)
{
      targetPage = targetPage ? targetPage : constXMLpage;
      url = targetPage + "?rand=" + (new Date().getTime()) + "&" + querystring;
      xmlhttp.Open("POST", url, true, "", "");
      xmlhttp.setRequestHeader("Content-Type","text/xml");
      xmlhttp.Send (sData);
      window.status = "Load in progress ........ ";
      xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4) {
                  if (resultHandlerFunction) {
                        eval(resultHandlerFunction);
                  } else {
                        XMLResponseHandler(xmlhttp.ResponseText,xmlhttp.ResponseXML);
                  }
                  window.status = "XML object loaded successfully.";
            }
      };
};

0
 
LVL 23

Accepted Solution

by:
Christopher Kile earned 250 total points
ID: 18803782
Mmm, yes, I did get confused.  

I'm now assuming that you've already parceled out request As String from the content sent to you, so request contains simply the XML you sent.

Dim xmlDoc as New System.Xml.XmlDocument
xmlDoc.Load(New StringReader(request))

This will load the xmlDoc for you. There is no Load function for an XML string itself, the only Load that accepts a string argument expects a URL in the string, not the XML itself, but there is a Load function for a TextReader, and a StringReader is a class derived from TextReader, so it is compatible.
0
 
LVL 23

Expert Comment

by:Christopher Kile
ID: 19056919
I'd bet quite a bit of, hmmm, vanity that my last post described his solution, which by this time seemed to me to be a method for loading an XMLDocument from a String, and that all that remained would be to debug and test.  
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

635 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question