经典 ASP SOAP 请求 - 从 Web 服务中提取数据的对象引用问题

Classic ASP SOAP Request - Object reference issue pulling data from web service

我看到的错误是:"Object reference not set to an instance of an object. at Service.a(String A_0, String A_1) at Service.GetBuildings(String UserName, String Password)"

因此,在我的 soap 请求中,我的用户名和密码似乎没有以适当的名称(分别为用户名和密码)发送,而是分别作为 A_0 和 A_1 发送。我不确定如何解决这个问题 - 所以我正在寻求建议。

我的代码如下所示:

<%
Dim objXMLHTTP : set objXMLHTTP = Server.CreateObject("MSXML2.XMLHTTP")

Dim strRequest, strResult, strFunction, strURL, strNamespace

'URL to SOAP namespace and connection URL
strNamespace = "http://DEA.EMS.API.Web.Service/"
strURL = "http://myserver/EMSAPI/"

'function you want to call
strFunction = "GetBuildings"
'strFunction = "test" 'no parameters required

strRequest ="<?xml version=""1.0"" encoding=""utf-8""?>" &_
      "<soap:Envelope" &_
      " xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""" &_
      " xmlns:api=""http://127.0.0.1/Integrics/Enswitch/API""" &_
      " xmlns:xsd=""http://www.w3.org/2001/XMLSchema""" &_
      " xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">" &_
        "<soap:Body>" &_
                "<GetBuildings>" &_
                    "<UserName>Myusername</UserName>" &_
                    "<Password>mypassword</Password>" &_
                "</GetBuildings>" &_
        "</soap:Body>" &_
      "</soap:Envelope>"


objXMLHTTP.open "POST", ""& strURL &"", True

objXMLHTTP.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
objXMLHTTP.setRequestHeader "Content-Length", Len(strRequest) 
objXMLHTTP.setRequestHeader "SOAPAction", strNamespace & strFunction


'send the request and capture the result
objXMLHTTP.send(strRequest)

'Set a timer to wait for response
set shell = CreateObject("WScript.Shell")
 t1 = timer()
 sleep(1)
 t2 = timer()
 response.write "waited "& t2-t1 &" secs"

 function sleep(seconds)
    if seconds>=1 then shell.popup "pausing",seconds,"pause",64
 end function


strResult = objXMLHTTP.responseText


'display the XML
response.write strResult

%>

我更新了我的代码以在 GetBuildings 节点中包含 'xmlns="http://DEA.EMS.API.Web.Service/"',它现在可以正常工作了。

所以代码现在看起来像这样:

<%
Dim objXMLHTTP : set objXMLHTTP = Server.CreateObject("MSXML2.XMLHTTP")

Dim strRequest, strResult, strFunction, strURL, strNamespace

'URL to SOAP namespace and connection URL
strNamespace = "http://DEA.EMS.API.Web.Service/"
strURL = "http://myserver/EMSAPI/"

'function you want to call
strFunction = "GetBuildings"
'strFunction = "test" 'no parameters required

strRequest ="<?xml version=""1.0"" encoding=""utf-8""?>" &_
      "<soap:Envelope" &_
      " xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""" &_
      " xmlns:api=""http://127.0.0.1/Integrics/Enswitch/API""" &_
      " xmlns:xsd=""http://www.w3.org/2001/XMLSchema""" &_
      " xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">" &_
        "<soap:Body>" &_
                "<GetBuildings xmlns=""http://DEA.EMS.API.Web.Service/"">" &_
                    "<UserName>Myusername</UserName>" &_
                    "<Password>mypassword</Password>" &_
                "</GetBuildings>" &_
        "</soap:Body>" &_
      "</soap:Envelope>"


objXMLHTTP.open "POST", ""& strURL &"", True

objXMLHTTP.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
objXMLHTTP.setRequestHeader "Content-Length", Len(strRequest) 
objXMLHTTP.setRequestHeader "SOAPAction", strNamespace & strFunction


'send the request and capture the result
objXMLHTTP.send(strRequest)

'Set a timer to wait for response
set shell = CreateObject("WScript.Shell")
 t1 = timer()
 sleep(1)
 t2 = timer()
 response.write "waited "& t2-t1 &" secs"

 function sleep(seconds)
    if seconds>=1 then shell.popup "pausing",seconds,"pause",64
 end function


strResult = objXMLHTTP.responseText


'display the XML
response.write strResult

%>