How to call web service using vbscript (synchronous)?

前端 未结 2 517
孤城傲影
孤城傲影 2021-01-02 12:19

Actually there many examples and I have used one of them. But it works asynchronous, I mean it is not waiting the function that I called to finish.

function          


        
2条回答
  •  有刺的猬
    2021-01-02 13:01

    If you're doing synchronous calls, you don't need the callback, and you can shrink the code into this:

    function ProcessSend() 
        Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP.4.0")
        Set oXMLDoc = CreateObject("MSXML2.DOMDocument")
    
        strEnvelope = "callNo=" & callNo & "&exp=" & exp
    
        call oXMLHTTP.open("POST", "http://localhost:11883/ServiceCall.asmx/"&posFirm, false)
        call oXMLHTTP.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
        call oXMLHTTP.send(strEnvelope)
    
        dim szResponse: szResponse = oXMLHTTP.responseText
        call oXMLDoc.loadXML(szResponse)
    
        if(oXMLDoc.parseError.errorCode <> 0) then
            'call msgbox("ERROR")
            response = oXMLHTTP.responseText&" "&oXMLDoc.parseError.reason
            'call msgbox(oXMLDoc.parseError.reason)
        else
            response = oXMLDoc.getElementsByTagName("string")(0).childNodes(0).text
        end if
    End Sub
    

提交回复
热议问题