Solved

xmlHttpRequest object is empty when it arrives at asp.net

Posted on 2006-11-28
17
440 Views
Last Modified: 2008-01-09
hello,

I have an activeX control which creats a DOM object and send it to an aspx page via the xmlHttpRequest object. Yet when i load the object into a DOM object on the server the request information seems to be empty. I aprechiate that using DOM in .NET is not the most efficent method of handling xml, but none the less i beleive this should work?

activex code to send DOM and xmlHttpRequest:

Set xmlHttpReq1 = New MSXML2.XMLHTTP30
xmlHttpReq1.Open "POST", strServerURL, False
xmlHttpReq1.send objDOM

receiving code on the aspx page:

xmlDoc = Server.CreateObject("Msxml2.DOMDocument")
xmlDoc.async = False
xmlDoc.validateOnParse = False
xmlDoc.resolveExternals = False
xmlDoc.Load(Request)

xmlDoc.Save(strXMLfile)

yet it saves an empty xml file....

I know the DOM object has created successfully at the client as i save the xml file for testing before sending it.

many thanks for any help.

0
Comment
Question by:wdhough
  • 9
  • 8
17 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 18027048
Hi wdhough,

Try:

xmlDoc.Load(Request.InputStream)

instead.

Tim Cottee
0
 

Author Comment

by:wdhough
ID: 18027291
thanks for the reply, but tis still empty.
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 18027316
wdhough,

The inputstream property should contain the posted DOM. Can you check that this is the case with a breakpoint and testing Request.InputStream.Length

Tim
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

 

Author Comment

by:wdhough
ID: 18027430
hmm,

I am getting an error "Value does not fall within the expected range" when trying to save the file or read the Request.InputStream.Length
0
 

Author Comment

by:wdhough
ID: 18027516
ok the length of the request is returning a value when I do not load it into the xmlDoc DOM object on the asp page. So if i jsut do:

strLength = (Request.InputStream.Length)

response.write(strLength)

i get a 6 figure value.

0
 
LVL 43

Expert Comment

by:TimCottee
ID: 18027548
wdhough,

Which at least means that it is indeed getting posted to the page, which you thought but is always good to check that.

Ok, it could be that using the msxml2 object is not the way to go. Can you try it with:

Dim xmlDoc As System.Xml.XmlDocument = New System.Xml.XmlDocument
xmlDoc.Load(Request.InputStream)
xmlDoc.Save(strXMLFile)

Tim
0
 

Author Comment

by:wdhough
ID: 18027737
ok thanks that worked a treat, but has caused problems with the next section of the code, what this does is read the saved xml file / and save the contents (bin.base64 encoded file) as its original file type

Dim xmlDoc1 As System.Xml.XmlDocument = New System.Xml.XmlDocument
xmlDoc1.Load(strXMLFile)
xmlDoc1.save(strXMLFile & "test.xml")


objStream = Server.CreateObject("ADODB.Stream")
objStream.Type = 1
objStream.Open

node = xmlDoc1.selectSingleNode("MESSAGE")
If Not(node.selectSingleNode("File") Is Nothing) Then
   objStream.Write = node.selectSingleNode("File").nodeTypedValue
End If

objStream.SaveToFile("c:\test.txt")
objStream.Close()
objStream = Nothing
xmlDoc1=nothing

session("OCX_UPLOADFILE") = session.sessionid & "." & strExtn

response.write(err.description)

but the error is now saying cannot write to file?

thanks again
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 18027764
wdhough,

That could be simply that the colder you are trying to write to is the root of the webserver and iis doesn't have permissions to write to this location.

You might be better creating a new folder c:\testing and assigning full control permissions to the iis account on this folder. Then give it a try again and see if that works.

Tim
0
 

Author Comment

by:wdhough
ID: 18027975
hmm im struggling a little with this,

i think the method im using to read the xml nodes might not be aplicable with New System.Xml.XmlDocument

it saves the file, but its empty adn an error message reports: "Public member nodeTypedValue on type XmlElement is not found"

any ideas?

0
 
LVL 43

Expert Comment

by:TimCottee
ID: 18028048
wdhough,

Without knowing the schema of the xml content, try something like this:

Dim xNode As System.Xml.XmlNode = xmlDoc1.SelectSingleNode("MESSAGE/File") 'Just a quicker way of getting to the relevant node using xpath
If Not(xNode Is Nothing) Then
    xNode.dataType = "bin.base64"
    objStream.Write xNode.nodeTypedValue
End If




Tim
0
 

Author Comment

by:wdhough
ID: 18028110
yeah thats kind of what i was doing anyway, but the error is : 'nodeTypedValue' is not a member of 'System.Xml.XmlNode'.
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 18028226
wdhough,

Fair point, mixing and matching xml implementations.

Just so I get it fully straight in my head here, you have in the node MESSAGE/File a byte stream representing file contents that you want to recreate as the original file on the server?

Tim
0
 

Author Comment

by:wdhough
ID: 18028268
thats exactly the case, and to further clarify I had this working in ASP and am now using ASP.net (hence) the changes.

So the final part of the conversion is to read the node value into the stream Wirte,

which is producing the above error.

thanks.
0
 
LVL 43

Accepted Solution

by:
TimCottee earned 250 total points
ID: 18028285
wdhough,

Dim xmlDoc1 As System.Xml.XmlDocument = New System.Xml.XmlDocument
xmlDoc1.Load(strXMLFile)
xmlDoc1.save(strXMLFile & "test.xml")
Dim xNode As System.Xml.XmlNode = xmlDoc1.SelectSingleNode("MESSAGE/File") 'Just a quicker way of getting to the relevant node using xpath
If Not(xNode Is Nothing) Then
'create a byte array from the base64 encoded string
    Dim aryFile() As Byte = Convert.FromBase64String(xNode.InnerXml)
    Dim f As IO.File
'open a filestream to write to the designated file
    Dim fs As IO.FileStream = f.OpenWrite("c:\testing\test.txt")
'Write the byte array in its entirety to the file
    fs.Write(aryFile, 0, aryFile.GetUpperBound(0))
'flush the filestream to disk and close
    fs.Flush()
    fs.Close()
End If

I think this should do the job (hopefully!)

Tim
0
 

Author Comment

by:wdhough
ID: 18028389
um.

"failed to map path now" yet that cant be a problem as reading and writing the file was fine before.
0
 

Author Comment

by:wdhough
ID: 18028434
ahh. got itworking.. Many thanks for your help.

Interesting to see the ways asp and aspx differ

thanks again.
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 18028457
wdhough,

You are welcome, glad I could help.

Tim
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
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…

828 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