-
Parsing SOAP XML with Classic ASP
I'm typically a LAMP stack developer, so I'm a little out of my comfort zone on this one. I'm working on a classic ASP site that is doing a SOAP based XML API connection. It's worked in the past, but now we're updating the API to connect to a different application. Problem is, I'm not able to get the API to work any more and I've hit a wall with a generic 500 error. I've got detailed error reporting turned on, and this is all it returns:
Code:
An error occurred on the server when processing the URL. Please contact the system administrator.
I set up a SOAP client before writing this API, and it tested good. I've run several tests since to be sure that it is still working. I've inserted statements describing what the code is doing at each step through execution to see which ones show up and which ones do not. It appears to break at this line:
Code:
isSuccess = objDoc.getElementsByTagName("Status").text
If it is helpful, here is the full document.
Code:
<%@ language=vbscript %>
<% Option Explicit %>
<%
'============================================================'
' Authenticate a representative using the representative's
' user name (RepDID or EmailAddress) and password.
'============================================================'
'----------------------------------------------------------'
' Process User Submitted Data
'----------------------------------------------------------'
If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
'Load form fields into variables
Response.Write "<p>Loading form fields into variables</p>"
Dim repUsername, repPassword
repUsername = Trim(Request.Form("rep-username"))
repPassword = Trim(Request.Form("rep-password"))
'Set up basic Validation...
Response.Write "<p>Validating form</p>"
If repUsername = "" Or repPassword = "" Then
Response.Redirect ("../index.asp?login=error#login")
Else
'----------------------------------------------------------'
' Compose SOAP Request
'----------------------------------------------------------'
Dim xobj, SOAPRequest
Set xobj = Server.CreateObject("Msxml2.ServerXMLHTTP")
xobj.Open "POST", "http://api.domain.com/3.0/Api.asmx", False
xobj.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
xobj.setRequestHeader "SOAPAction", "http://api.domain.com/AuthenticateCustomer"
SOAPRequest = _
"<?xml version=""1.0"" encoding=""utf-8""?>" &_
"<x:Envelope xmlns:x='http://schemas.xmlsoap.org/soap/envelope/' xmlns:api='http://api.domain.com/'>"&_
"<x:Header>" &_
"<api:ApiAuthentication>" &_
"<api:LoginName>string</api:LoginName>" &_
"<api:Password>string</api:Password>" &_
"<api:Company>string</api:Company>" &_
"<api:ApiAuthentication>" &_
"</x:Header>" &_
"<x:Body>" &_
"<api:AuthenticateCustomerRequest>" &_
"<api:LoginName>"&repUsername&"</api:LoginName>" &_
"<api:Password>"&repPassword&"</api:Password>" &_
"</api:AuthenticateCustomerRequest>" &_
"</x:Body>" &_
"</x:Envelope>"
Response.Write "<p>Sending SOAP envelope</p>"
xobj.send SOAPRequest
'----------------------------------------------------------'
' Retrieve SOAP Response
'----------------------------------------------------------'
Dim strReturn, objDoc, isSuccess
Response.Write "<p>Receiving SOAP response</p>"
strReturn = xobj.responseText 'Get the return envelope
Set objDoc = CreateObject("Microsoft.XMLDOM")
objDoc.async = False
Response.Write "<p>Loading XML</p>"
objDoc.LoadXml(strReturn)
Response.Write "<p>Parsing XML</p>"
isSuccess = objDoc.getElementsByTagName("Status")("Success").text
'----------------------------------------------------------'
' If user is valid set Session Authenticated otherwise
' restrict user and redirect to the index page and show error
'----------------------------------------------------------'
Response.Write "<p>Authenticating...</p>"
If isSuccess = "Success" Then
Session("Authenticated") = 1
'Session.Timeout = 1 '60 'Expire session 1 hours from current time
Response.Redirect ("../welcome.asp#AdvancedTrainingVideos")
Else
Session("Authenticated") = 0
Response.Redirect ("../index.asp?login=error#login")
End IF 'END - isSuccess
End IF ' END - Basic Validation...
End IF 'END - REQUEST_METHOD POST
%>
Any insights are very welcome.
-
Re: Parsing SOAP XML with Classic ASP
I'm neither a vbscript nor soap person, but I offer this.
In the first part of your post you give
Code:
isSuccess = objDoc.getElementsByTagName("Status").text
but in the full document you give
Code:
isSuccess = objDoc.getElementsByTagName("Status")("Success").text
-
Re: Parsing SOAP XML with Classic ASP
Quote:
Originally Posted by
2kaud
I'm neither a vbscript nor soap person, but I offer this.
In the first part of your post you give
Code:
isSuccess = objDoc.getElementsByTagName("Status").text
but in the full document you give
Code:
isSuccess = objDoc.getElementsByTagName("Status")("Success").text
Good catch. I've been doing a number of experiments to see if I can get it to work. At one point I entered in the value of the tag as well as the tag name to see if that would do it. The original API from which I modified this one had a boolean reponse in that second field, which was (0). This response is not boolean, but a string "Success". Unfortunately that didn't fix it. Not sure if it broke it more, but it definitely didn't fix it.
-
Re: Parsing SOAP XML with Classic ASP
Here's where I'm at. I've installed an ASP host on my computer so I can run locally and get more detailed error reporting. The error is as follows:
Quote:
Microsoft VBScript runtime error '800a01c2'
Wrong number of arguments or invalid property assignment
/inc/verify.asp, line 69
The line of code in question is as follows:
Code:
isSuccess = objDoc.getElementsByTagName("Status")
I've been toying with this line for quite a while now and nothing I do seems to work, though I have been able to generate more types of errors!
-
Re: Parsing SOAP XML with Classic ASP
getElementsByTagName returns a list of objects, not a Boolean value.
Refer to https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx
-
Re: Parsing SOAP XML with Classic ASP
Quote:
Originally Posted by
Arjay
Hi Arjay! The return I'm getting is supposed to be a string, not boolean, so it sounds like I'm using the right method. However, I am having difficulty figuring out how to take that returned value and successfully load it into my "isSuccess" variable.
-
Re: Parsing SOAP XML with Classic ASP
-
Re: Parsing SOAP XML with Classic ASP
Quote:
Originally Posted by
Auciker
Hi Arjay! The return I'm getting is supposed to be a string, not boolean, so it sounds like I'm using the right method. However, I am having difficulty figuring out how to take that returned value and successfully load it into my "isSuccess" variable.
Okay, getElementsByTagName returns a list of objects, not a string.
-
Re: Parsing SOAP XML with Classic ASP
Quote:
Originally Posted by
Arjay
Okay, getElementsByTaskName returns a list of objects, not a string.
What is your recommendation on how I could alter the code to get it to work?
BTW, you keep entering "getElementsByTaskName", but the method I'm using is "getElementsByTagName". Is this a typo on your part?
-
Re: Parsing SOAP XML with Classic ASP
Quote:
Originally Posted by
Auciker
What is your recommendation on how I could alter the code to get it to work?
BTW, you keep entering "getElementsByTaskName", but the method I'm using is "getElementsByTagName". Is this a typo on your part?
Sorry, I had typo'd the name of the method, but had you clicked on the link I referred you to, you would have seen that it was getElementsByTagName. The link shows the method returns an array of objects and includes a code snippet that shows you how to access the first object.
-
Re: Parsing SOAP XML with Classic ASP
I assumed it was a typo, but I wanted to be sure we're on the same page.
I did visit the page, but unfortunately it is not clear to me exactly what I'm supposed to do. As with most code documentation, but I found it to be too obtuse for me. The examples are in Javascript and C++ and I'm working with ASP and VBS.
-
Re: Parsing SOAP XML with Classic ASP
Quote:
What is your recommendation on how I could alter the code to get it to work?
From looking at the article in post #5, I would consider
Code:
isSuccess = objDoc.getElementsByTagName("Status")
...
If isSuccess.item(0).text = "Success" Then
or possibly
Code:
isSuccess = objDoc.getElementsByTagName("Status").item(0).text
...
If isSuccess = "Success" Then
-
Re: Parsing SOAP XML with Classic ASP
Quote:
Originally Posted by
2kaud
From looking at the article in post #5, I would consider
Code:
isSuccess = objDoc.getElementsByTagName("Status")
...
If isSuccess.item(0).text = "Success" Then
or possibly
Code:
isSuccess = objDoc.getElementsByTagName("Status").item(0).text
...
If isSuccess = "Success" Then
Thanks 2kaud. Unfortunately it's now returning the following error:
Code:
Microsoft VBScript runtime error '800a01a8'
Object required: '[object]'
-
Re: Parsing SOAP XML with Classic ASP
Which line is causing the error?
-
Re: Parsing SOAP XML with Classic ASP
Quote:
Originally Posted by
Auciker
Thanks 2kaud. Unfortunately it's now returning the following error:
Code:
Microsoft VBScript runtime error '800a01a8'
Object required: '[object]'
If objDoc.GetElementsByTagName("Status") doesn't find any objects, then attempting to access the first object in a list (with item(0)) is going to result in an error. You need to check if isSuccess is null and isSuccess.item is null (or has values).
-
Re: Parsing SOAP XML with Classic ASP
Quote:
Originally Posted by
2kaud
Which line is causing the error?
Sorry, same line.
-
Re: Parsing SOAP XML with Classic ASP
Quote:
Originally Posted by
Arjay
If objDoc.GetElementsByTagName("Status") doesn't find any objects, then attempting to access the first object in a list (with item(0)) is going to result in an error. You need to check if isSuccess is null and isSuccess.item is null (or has values).
OK, I follow. How do you suggest I write that? Please keep in mind that this is not a language I'm used to dealing with, so the most specific answer possible would be most helpful.
-
Re: Parsing SOAP XML with Classic ASP
Which version of my suggestions in post #12 are you trying? If the first suggestion and the error line is still the one containing .GetElementsByTagName() then there is still an issue with .GetElementsByTagName().
If you are using the second suggestion, then try using the first and see if the error moves to the if statement.
-
Re: Parsing SOAP XML with Classic ASP
Quote:
Originally Posted by
Auciker
OK, I follow. How do you suggest I write that? Please keep in mind that this is not a language I'm used to dealing with, so the most specific answer possible would be most helpful.
I don't code in this language either, but it's probably something like:
Code:
isSuccess = objDoc.getElementsByTagName("Status")
...
If isSuccess = Null AND isSuccess.item(0).text = "Success" Then
Not sure the syntax of how to check for null and do an AND statement, but that is the gist of it.
-
Re: Parsing SOAP XML with Classic ASP
A sister site to this one has a forum for ASP and VBScript. You might like to try posting there
http://www.vbforums.com/forumdisplay...-ASP-VB-Script
-
Re: Parsing SOAP XML with Classic ASP
Quote:
Originally Posted by
2kaud
Which version of my suggestions in post #12 are you trying? If the first suggestion and the error line is still the one containing .GetElementsByTagName() then there is still an issue with .GetElementsByTagName().
If you are using the second suggestion, then try using the first and see if the error moves to the if statement.
I've tried the first suggestion. Moving it to the second line won't work, as it has to get passed line 66 (fatal error line) to get to the "fixed" line on 68.
Code:
Microsoft VBScript runtime error '800a01a8'
Object required: '[object]'
/inc/verify.asp, line 66
Line 66 currently reads:
Code:
isSuccess = objDoc.getElementsByTagName("Status").item(0).text
-
Re: Parsing SOAP XML with Classic ASP
Quote:
Originally Posted by
Arjay
I don't code in this language either, but it's probably something like:
Code:
isSuccess = objDoc.getElementsByTagName("Status")
...
If isSuccess = Null AND isSuccess.item(0).text = "Success" Then
Not sure the syntax of how to check for null and do an AND statement, but that is the gist of it.
The change you're recommending is on line 68, but the code stops at line 66.
-
Re: Parsing SOAP XML with Classic ASP
Quote:
Originally Posted by
2kaud
I just did so, thanks for the direction!
-
Re: Parsing SOAP XML with Classic ASP
Try changing line 66 to
Code:
isSuccess = objDoc.getElementsByTagName("Status")
Does the error move to a different line or stay on line 66?
-
Re: Parsing SOAP XML with Classic ASP
Quote:
Originally Posted by
2kaud
Try changing line 66 to
Code:
isSuccess = objDoc.getElementsByTagName("Status")
Does the error move to a different line or stay on line 66?
I did try that early on, but it gave the following error:
Code:
Microsoft VBScript runtime error '800a01c2'
Wrong number of arguments or invalid property assignment
/inc/verify.asp, line 66
I just tried it again with the same results.
-
Re: Parsing SOAP XML with Classic ASP
Quote:
Originally Posted by
Auciker
The change you're recommending is on line 68, but the code stops at line 66.
Fantastic, is objDoc null?
-
Re: Parsing SOAP XML with Classic ASP
Quote:
Originally Posted by
Arjay
Fantastic, is objDoc null?
No, it should exist and be carrying the value "Success". This is the case in the API client I have successfully tested. I set an If/Else statement that if it returns any answer that does not include
Code:
<Status>Success</Status>
it is taken as a failed authentication and should redirect to the login#error page. This should include null.
-
Re: Parsing SOAP XML with Classic ASP
Quote:
Originally Posted by
Auciker
No, it should exist and be carrying the value "Success". This is the case in the API client I have successfully tested. I set an If/Else statement that if it returns any answer that does not include
Code:
<Status>Success</Status>
it is taken as a failed authentication and should redirect to the login#error page. This should include null.
You need to check to make sure what you think is getting loaded into the DOM is actually getting loaded. Back up and write out the strReturn value to the screen before loading the xmldoc.
Code:
Response.Write "<p>" + strReturn + "</p>"
Btw, I found a website where you can test script online. I was able to get something working in javascript, but not in VBScript. In fact, the VBScript samples on the site wouldn't work in my IE11 browser.
See http://www.xmlfiles.com/dom/dom_access.asp