Monday, March 8, 2010

Vb Script to call a web service

Dim oXMLDoc, oXMLHTTP

Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP.3.0")
Set oXMLDoc = CreateObject("MSXML2.DOMDocument")
Msgbox("Calling WebService ")
oXMLHTTP.onreadystatechange = getRef("HandleStateChange")
call oXMLHTTP.open ("POST","http://localhost:1673/WebService1.asmx/Helloworld",false)
call oXMLHTTP.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
'send input parameters
oXMLHTTP.send "a=1"


Sub HandleStateChange
if(oXMLHTTP.readyState = 4) then
dim szResponse
szResponse = oXMLHTTP.responseText
call oXMLDoc.loadXML(szResponse)
if(oXMLDoc.parseError.errorCode <> 0) then
call msgbox(oXMLDoc.parseError.reason)
else
msgbox(oXMLDoc.getElementsByTagName("string")(0).childNodes(0).text)
end if
end if
End Sub