[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

xmlHttpRequest object is empty when it arrives at asp.net

Posted on 2006-11-28
17
Medium Priority
?
453 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
[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
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 1000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

650 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