• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1655
  • Last Modified:

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,

0
oxford100
Asked:
oxford100
  • 5
  • 5
1 Solution
 
sybeCommented:
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

0
 
oxford100Author Commented:
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?

0
 
sybeCommented:
> 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.

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
oxford100Author Commented:
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.
0
 
sybeCommented:
> 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.
0
 
oxford100Author Commented:
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

0
 
sybeCommented:
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

0
 
oxford100Author Commented:
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

0
 
sybeCommented:
I'd use XPath to search in an XML file, not RegEx, or maybe simply loop through the nodes.

Just some basic idea below, the actual code depends on the structure of the returned xml. You also need to have the XML as an object, not as a string.


Set oNodeList = oXML.documentElement.ChildNodes
For each oNode in oNodeList
   'extract the car id's and the prices
   ' plus some code to find the highest and lowest price
Next

Open in new window

0
 
oxford100Author Commented:
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!
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.

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