[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 455
  • Last Modified:

xmlHttpRequest object is empty when it arrives at asp.net

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
wdhough
Asked:
wdhough
  • 9
  • 8
1 Solution
 
TimCotteeCommented:
Hi wdhough,

Try:

xmlDoc.Load(Request.InputStream)

instead.

Tim Cottee
0
 
wdhoughAuthor Commented:
thanks for the reply, but tis still empty.
0
 
TimCotteeCommented:
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.

 
wdhoughAuthor Commented:
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
 
wdhoughAuthor Commented:
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
 
TimCotteeCommented:
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
 
wdhoughAuthor Commented:
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
 
TimCotteeCommented:
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
 
wdhoughAuthor Commented:
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
 
TimCotteeCommented:
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
 
wdhoughAuthor Commented:
yeah thats kind of what i was doing anyway, but the error is : 'nodeTypedValue' is not a member of 'System.Xml.XmlNode'.
0
 
TimCotteeCommented:
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
 
wdhoughAuthor Commented:
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
 
TimCotteeCommented:
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
 
wdhoughAuthor Commented:
um.

"failed to map path now" yet that cant be a problem as reading and writing the file was fine before.
0
 
wdhoughAuthor Commented:
ahh. got itworking.. Many thanks for your help.

Interesting to see the ways asp and aspx differ

thanks again.
0
 
TimCotteeCommented:
wdhough,

You are welcome, glad I could help.

Tim
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 9
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now