经典的asp和soap响应-如何处理名称空间中更改的前缀?

时间:2018-11-05 10:20:11

标签: soap asp-classic wsdl

我继承了使用Web服务的经典ASP页面,这是我相对较新的东西。请求和响应工作正常,但我注意到在wsdl和我阅读它之间的名称空间中添加了一个前缀。因此,命名空间<FirstName>会变成<ns2:FirstName>或有时是<ns3:FirstName>或有时只是<FirstName>。它是完全相同的元素,但是前缀经常更改。
有人告诉我我正在读取响应“原始”,并且我需要过滤掉这些额外生成的前缀,但是我不知道该怎么做。 这是我如何使用Web服务的代码片段(为了简化起见,对某些内容进行了修改):

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)。任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:0)

您能否使用VBScript的Replace函数将Firstname标签更改为shelve

例如

<Firstname>

NB我通常建议调用MSXML的版本6而不是版本3-这是最新版本