Link to home
Start Free TrialLog in
Avatar of wdhough
wdhough

asked on

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.

Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

Hi wdhough,

Try:

xmlDoc.Load(Request.InputStream)

instead.

Tim Cottee
Avatar of wdhough
wdhough

ASKER

thanks for the reply, but tis still empty.
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
Avatar of wdhough

ASKER

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
Avatar of wdhough

ASKER

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.

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
Avatar of wdhough

ASKER

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
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
Avatar of wdhough

ASKER

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?

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
Avatar of wdhough

ASKER

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

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of wdhough

ASKER

um.

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

ASKER

ahh. got itworking.. Many thanks for your help.

Interesting to see the ways asp and aspx differ

thanks again.
wdhough,

You are welcome, glad I could help.

Tim