Link to home
Start Free TrialLog in
Avatar of oxford100
oxford100

asked on

classic asp and soap

Hello,

I have a classic asp page that successfully makes a soap request and in return I get my soap response.  I'm able to manipulate the data that gets returned no problem.  

What I'm trying to do now, is make repetitive soap requests from my asp page, because there is a limit on the amount of information that can be passed in with the soap request.

I did try looping through a recordset and passing in 20 variables at a time in my soap request.  So when the first 20 get processed, my program automatically makes another soap request to get the next 20 but it is throwing an error saying that a top level root element already exists.

Any ideas on this one or how I could go about making multiple soap requests from the same page?

Thanks,

Avatar of sybe
sybe

Not totally sure if this is what you are asking, but see the code below.
Do While Not oRS.EOF
    ' start new soap request
    For i = 1 To 20
    	' add item to soap
        oRS.MoveNext
        If or.EOF Then Exit For
    Next
    ' send soap request (end process response)
Loop

Open in new window

Avatar of oxford100

ASKER

Sybe,

Thanks for looking!  The code you posted is very similar to what I already have in place which helps me to confirm that I'm on the right track.

Just so you know, the returned result is xml and I use asp regex to parse the xml and throw the information I want into another db.The first time your code is run, it's fine and returns results.  When looping through and doing the next 20, the page throws an error saying that a top level root element already exists. Any ideas on that?

> the page throws an error saying that a top level root element already exists

XML can have only one top level root element.

this is fine
---------------
<xml>
    <nodes />
</xml>
---------------


but this is wrong
---------------
<xml>
    <nodes />
</xml>
<xml>
    <nodes />
</xml>
---------------


That is what the error message says.
Somehow you are using the same XML object to attach a second root element to. You can not do that. In stead you have to send the first created soap and process the response. And then send another (newly created) soap object, which its own root element.

Agreed on xml only being able to have one top level element.  So how do I get around that?

And then send another (newly created) soap object, which its own root element.?
Does that mean creating a new page, or can I use the same page to get multiple soap requests.

objXMLHTTP1
$159.00
$99.00

The above is returned ok, but then after this the errors being returned look like this:

GET THE NEXT SET
objXMLHTTP2
soap:Client Server was unable to read request. --> There are multiple root elements. Line 1, position 1215.

GET THE NEXT SET
objXMLHTTP3
soap:Client Server was unable to read request. --> There are multiple root elements. Line 1, position 1215.
> can I use the same page to get multiple soap requests

You should.
It is hard to tell where exactly you are going wrong without seeing the actual code.
Below is some code that hopefully helps?
<%
' In this section I get some variables that I pass into my request
 
while not rs33.EOF
 
SET  objXMLHTTP = Server.CreateObject("Msxml2.XMLHTTP")
 
strMethodPkg = strMethodPkg & "<soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">"
strMethodPkg = strMethodPkg & "<soap:Body>"
strMethodPkg = strMethodPkg & "<xmlFormattedString>"
strMethodPkg = strMethodPkg & "&lt;SomeStuffGoesHeres&gt;"
 
 
 Count = 0
    Do While Not rs33.EOF And Count < 20
		strMethodPkg = strMethodPkg & "&lt;Car CarID=""" & rs33("carID") & """/&gt;"
        Count = Count + 1
        rs33.MoveNext
    Loop
 
strMethodPkg = strMethodPkg & "</xmlFormattedString>"
strMethodPkg = strMethodPkg & "</SubmitRequest>"
strMethodPkg = strMethodPkg & "</soap:Body>"
strMethodPkg = strMethodPkg & "</soap:Envelope>"
 
objXMLHTTP.open "POST", "http://test.com", False
objXMLHTTP.setRequestHeader "Host", "test.com"
objXMLHTTP.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
objXMLHTTP.setRequestHeader "Content-Length", Len(strMethodPkg)
objXMLHTTP.setRequestHeader "SOAPAction", "http://test.com/cars/"
 
Call objXMLHTTP.send(strMethodPkg)
 
strMethodResultXML = objXMLHTTP.responseText
 
response.write strMethodResultXML & "<br><br><U>GET THE NEXT SET</U><br>"
 
Set objXMLHTTP = Nothing
Set strMethodResultXML = Nothing
 
counter = counter + 1
 
 
	Wend
 
	rs33.Close
	Set rs33 = Nothing
 
%>

Open in new window

It is because the value of variable strMethodPkg is growing with every loop.
The first line in the loop should be

strMethodPkg = "start the string from scratch"

and not

strMethodPkg = strMethodPkg & "start the string from scratch"

' change the line below:
strMethodPkg = strMethodPkg & "<soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">"
 
 
' it should be:
strMethodPkg = "<soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">"

Open in new window

Sybe,

That did it!  Thank you.  The points are yours, but I do have a related question and since your in tune with what I'm doing here, I was hoping you could take this a bit further? If not, I'll award you the points and open another question.  If you can take this further, here's what I'm trying to do...

So in the returned xml, a carID is returned and a bunch of prices.  I've been using the regex method to write to the screen all the carID's that are returned and then all the prices for all the cars.  What I need to do is extract the the first carID and get the lowest price and the highest price prior to finding the next carID and it's associated prices. Does that make sense?  Below is the code that I was using for the regex.




With RegularExpressionObject2
.Pattern = "CarID=" & Chr(34) & "([^" & Chr(34) & "]+)"
.IgnoreCase = True
.Global = True
End With
 
	Set expressionmatch2 = RegularExpressionObject2.Execute(StringToSearch)
 
		if expressionmatch2.Count > 0 Then
			For Each expressionmatched in expressionmatch2
				cID = Mid(expressionmatched.Value,10)
				response.write "<b>" & hID & "</b><br/>"
			Next
		end If
 
Set RegularExpressionObject1 = New RegExp
 
With RegularExpressionObject1
.Pattern = "Price=" & Chr(34) & "([^" & Chr(34) & "]+)"
.IgnoreCase = True
.Global = True
End With
 
	Set expressionmatch1 = RegularExpressionObject1.Execute(StringToSearch)
 
		if expressionmatch1.Count > 0 Then
			For Each expressionmatched in expressionmatch1
				pNum = Mid(expressionmatched.Value,8)
				response.write cNum & "<br/>"
			Next
		end If

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of sybe
sybe

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
sybe.  Going to award the points from the previous help you gave me and will probably post more questions as I investigate using the xPath option or looping.

Thank you!