Quantcast
Channel: VBForums - ASP, VB Script
Viewing all articles
Browse latest Browse all 688

Parsing SOAP XML with Classic ASP

$
0
0
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. 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 set up a local ASP server to try to get the most detailed error possible. Here's what I get:
Code:

Microsoft VBScript runtime error '800a01a8'

Object required: '[object]'

/inc/verify.asp, line 66

Line 66 is as follows:
Code:

isSuccess = objDoc.getElementsByTagName("Status").item(0).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").item(0).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.

Viewing all articles
Browse latest Browse all 688

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>