AutoIT – Getting data from a Web Service

Web Services are a nice feature on the internet. But accessing it as a scripter is not so obvious.

Let’s see here how it goes.

First we need to have the URL of the Web Service and peak into the SOAP Envelop structure.


This API returns 4 methods to retrieve data back depending on some input.

Let’s take the GetInfoByZIP for Example. You see and input field and a SOAP envelope structure which we need later on.


If you enter some ZIP CODE you will get an XML response.


But if we want to script is we need to get WSDL definition.

This site offers an online WSDL browser.


Look at the ?WSDL extention after the URL

Now we have everuthin we setup our script to get the data.


In the script I added some debug information output.

You can capture the Debug XML response, and add it to an XML Parser for further investigation.


Once you know how the XML is formatted, we can capture the data in it.


Here is the full code.

Dim $objHTTP
Dim $strEnvelope
Dim $strReturn
Dim $objReturn
Dim $strQuery
Dim $strValue

$strValue = InputBox("Testing", "Enter your new value here.", 60007)

; Initialize COM error handler
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

$objHTTP = ObjCreate("Microsoft.XMLHTTP")
$objReturn = ObjCreate("Msxml2.DOMDocument.3.0")

; Create the SOAP Envelope
$strEnvelope = '<?xml version="1.0" encoding="utf-8"?>' & _
'<soap:Envelope xmlns:xsi="" xmlns:xsd="" xmlns:soap="">' & _
'<soap:Body>' & _
'<GetInfoByZIP xmlns="http://www.webserviceX.NET">' & _
'<USZip>'&$strValue&'</USZip>' & _
'</GetInfoByZIP>' & _
'</soap:Body>' & _

; Set up to post to the server
$ ("post", "", False)

; Set a standard SOAP/ XML header for the content-type
$objHTTP.setRequestHeader ("Content-Type", "text/xml")

; Set a header for the method to be called
$objHTTP.setRequestHeader ("SOAPMethodName", "urn:myserver/soap:TaxCalculator#Getsalestax")

ConsoleWrite("Content of the Soap envelope : "& @CR & $strEnvelope & @CR & @CR)

; Make the SOAP call
$objHTTP.send ($strEnvelope)

; Get the return envelope
$strReturn = $objHTTP.responseText

ConsoleWrite("-----------" & @CRLF)
ConsoleWrite ("Debug Response : "& @CR & $strReturn & @CR & @CR)
ConsoleWrite("-----------" & @CRLF)

; Load the return envelope into a DOM
$objReturn.loadXML ($strReturn)

ConsoleWrite("Return of the SOAP Msg : " & @CR & @CR & $objReturn.XML & @CR & @CR)

; Query the return envelope
$strQuery = "SOAP:Envelope/SOAP:Body"


$Soap = $objReturn.Text

MsgBox(0,"SOAP Response","The Response is  : " & $Soap)

Func MyErrFunc()
  Msgbox(0,"COM Test","We intercepted a COM Error !"       & @CRLF  & @CRLF & _
			 "err.description is: "    & @TAB & $oMyError.description    & @CRLF & _
			 "err.windescription:"     & @TAB & $oMyError.windescription & @CRLF & _
			 "err.number is: "         & @TAB & $HexNumber              & @CRLF & _
			 "err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
			 "err.scriptline is: "     & @TAB & $oMyError.scriptline     & @CRLF & _
			 "err.source is: "         & @TAB & $oMyError.source         & @CRLF & _
			 "err.helpfile is: "       & @TAB & $oMyError.helpfile       & @CRLF & _
			 "err.helpcontext is: "    & @TAB & $oMyError.helpcontext _

In Powershell this is only a few lines 2 to be exact.But at least now you know what is going on behind the scene. Smile

See Example here


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: