Solved

xmlHttpRequest object is empty when it arrives at asp.net

Posted on 2006-11-28
17
437 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
 

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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

743 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

14 Experts available now in Live!

Get 1:1 Help Now