【发布时间】:2018-11-06 08:29:12
【问题描述】:
我继承了一个使用 web 服务的经典 asp 页面,这是我相对较新的东西。请求和响应工作正常,但我注意到前缀被添加到 wsdl 和我阅读它之间的某个名称空间。所以命名空间<FirstName> 将变成<ns2:FirstName> 或有时<ns3:FirstName> 或有时只是<FirstName>。它是完全相同的元素,但前缀经常变化。
我被告知我正在阅读“原始”响应,我需要过滤掉这些额外生成的前缀,但我不知道如何。
这是我如何使用 Web 服务的代码 sn-p(为了保持简单,我们对一些内容进行了修改):
Dim oXmlHTTP, objxml, SOAPRequest, SOAPResponse
Set oXmlHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP.3.0")
oXmlHTTP.open "POST", "http://something.com/something/services/something?wsdl", False
oXmlHTTP.setRequestHeader "Content-Type", "text/xml; charset=UTF-8"
SOAPRequest = _
"<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:head='http://header.something.com" xmlns:ser='http://service.something.com' xmlns:add='http://service.something.com/domain/address'>" &_
"<soapenv:Body>" &_
"<ser:getInfo>" &_
"<add:ID>123</add:ID>" &_
"</ser:getInfo>" &_
"</soapenv:Body>" &_
"</soapenv:Envelope>"
On Error Resume Next
oXmlHTTP.send SOAPRequest
If Err.Number Then
Response.Write("Error: " & Err.Description)
Err.Clear
Else
SOAPResponse = oXmlHTTP.responseText
End If
On Error Goto 0
If LEN(SOAPResponse) > 0 then
Set objxml = Server.CreateObject("MSXML2.DOMDocument.3.0")
objxml.async = False
objxml.load (oXmlHTTP.responseXML)
If objxml.parseError.errorCode <> 0 Then
Response.Write("XML error")
End If
'This is where the "error" will occur, as the <Firstname> sometimes isn't recognized, and I must search for e.g. <ns2:Firstname> instead
Set nodeList = objxml.getElementsByTagName("FirstName")
SizeofObject = nodeList.length-1
For i = 0 To (SizeofObject)
Response.Write ("Name: " & objxml.getElementsByTagName("FirstName").item(i).Text)
Next
End If
Set oXmlHTTP = Nothing
SOAPRequest = ""
SOAPResponse = ""
如何忽略这些可能出现的“随机”前缀?在经典 asp 中使用 web 服务调用是否有更好的做法? (现在不能选择更改为 .NET)。任何帮助表示赞赏。
【问题讨论】:
标签: soap asp-classic wsdl