xmlvbscriptasp-classicwindows-server-2012iis-8.5

Why am I getting a '800a01a8' Object required error when loading XML from 3rd party API?


I started getting this error on our production Windows 2012 server running IIS 8.5:

Microsoft VBScript runtime error '800a01a8'

Object required: 'MERCHANTmydoc.documentElement'

The error seems to occur on this line:

Set MERCHANTmydoc=Server.CreateObject("Microsoft.xmlDOM")

No code was changed and the API has not changed (according to merchant support) when this started. I tested this same API string (inserting valid values) with Postman and got a valid reply, so I know the credentials work. I am beginning to suspect an issue with IIS, but don't know how to proceed.

MERCHANTstrXML = "<txn><ssl_merchant_ID>" & MERCHANT_ID & "</ssl_merchant_ID><ssl_user_id>" & MERCHANT_USER & "</ssl_user_id><ssl_pin>" & MERCHANT_PIN & "</ssl_pin><ssl_transaction_type>ccsale</ssl_transaction_type><ssl_card_number>" & merchant_card_number & "</ssl_card_number><ssl_exp_date>" & merchant_exp_date & "</ssl_exp_date><ssl_amount>" & merchant_trans_amount & "</ssl_amount><ssl_salestax>" & merchant_sales_tax & "</ssl_salestax>" & merch_indicator_var & "<ssl_cvv2cvc2>" & merchant_cvv2_code & "</ssl_cvv2cvc2><ssl_invoice_number>" & merchant_invoice_number & "</ssl_invoice_number><ssl_customer_code>" & merchant_customer_code & "</ssl_customer_code><ssl_first_name>" & merchant_first_name & "</ssl_first_name><ssl_last_name>" & merchant_last_name & "</ssl_last_name><ssl_avs_address>" & merchant_add1 & "</ssl_avs_address><ssl_avs_zip>" & merchant_zip & "</ssl_avs_zip><ssl_email>" & merchant_email & "</ssl_email><ssl_test_mode>" & MERCHANT_Test_Mode & "</ssl_test_mode></txn>"
        
if session("CHARGED") = "YES" then
    'Do nothing
else
    Set MERCHANTxmlhttp = Server.CreateObject("MSXML2.ServerXMLHTTP")

MERCHANTxmlhttp.Open "POST","https://api.convergepay.com/VirtualMerchant/processxml.do?xmldata=" & MERCHANTstrXML,false

MERCHANTxmlhttp.send 

MERCHANTresponsexml = MERCHANTxmlhttp.responseText  

Set MERCHANTmydoc=Server.CreateObject("Microsoft.xmlDOM")
MERCHANTmydoc.async= false
MERCHANTmydoc.loadxml(MERCHANTresponsexml)

I found a script to test xml requests and got this error: Sending XML data to http://localhost:8096/cart/receive3.asp msxml3.dll error '80072efd'

A connection with the server could not be established

/cart/post3.asp, line 12

These are the scripts I used

<%

    '// URL to which to send XML data
    URL="http://localhost:8096/cart/receive3.asp"

    Response.Write "Sending XML data to " & URL & "<br/>"

    information = "<Send><UserName>test</UserName><PassWord>user</PassWord><Data>100</Data></Send>"
    Set xmlhttp = server.Createobject("MSXML2.ServerXMLHTTP")
    xmlhttp.Open "POST", url, false
    xmlhttp.setRequestHeader "Content-Type", "text/xml" 
    xmlhttp.send information

    '// Report the response from the called page
    response.write "Response received:<hr/><span style='color:blue'>" & xmlhttp.ResponseText & "</span><hr/>"

%>
<%

    Dim objXmlRequest
    Set objXmlRequest = Server.CreateObject("MSXML2.DOMDOCUMENT.3.0")

    IF objXmlRequest.Load (Request) THEN

      'GET THE REQUEST FROM CLIENT
      strQuery = "//UserName"
      Set oNode = objXmlRequest.selectSingleNode(strQuery)
      strActionName = oNode.Text
      response.write "success! user name is " & strActionName  

    ELSE

        Response.Write "Failed to load XML file, reason: " & objXmlRequest.parseError.reason 

    END IF
%>

Solution

  • The actual cause of the Object required (which was the initial question) is to do with the assumptions being made about the call out to the 3rd party API.

    After calling Send() on the XmlHttp object you should always check what is being returned before doing anything with it, the easiest way is to check the Status in the response that is returned.

    Option Explicit
    Dim request_xml: request_xml= "..." 'Assumed valid XML
    Dim xhr: Set xhr = Server.CreateObject("MSXML2.ServerXMLHTTP")
    Call xhr.Open ("POST","https://api.convergepay.com/VirtualMerchant/processxml.do?xmldata=" & request_xml, False)
    Call xhr.Send()
    
    'Check we have a success HTTP response code.
    If Left(xmlhttp.Status, 1) = 2 Then
      Dim response_xml: response_xml = xhr.responseText
      Dim xml: Set xml = Server.CreateObject("Microsoft.XMLDOM")
      xml.Async= False
      Call xml.LoadXml(response_xml)
    Else
      Call Response.Write("Error calling API - " & xhr.Status)
    End If
    

    The error occurs because the API is not sending back a valid XML response so LoadXml() fails. This means when calling MERCHANTmydoc.documentElement the MERCHANTmydoc isn't instantiated.


    Useful Links