Solved

Read XML request in ASP.NET

Posted on 2007-03-19
15
622 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
  • 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now