Solved

Read XML request in ASP.NET

Posted on 2007-03-19
15
636 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

820 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