WebSevice call from vbs script

There are times when you have to integrate with a system. You do everything as documentation said you should, you run your integration test and… fail, …miserably, …with non-informative exception and no clue whatsoever.

You tell the „other guys” that either their system does not work as expected or the documentation is crappy, but „they” blame it on faults in system your develop.

Ping-pong. Ping-pong.

„They” will never look at your code, give you any hint what you maybe doing wrong, because there to busy, they’re „java” guys, or just RTFM. They sometimes throw at you some crappy „reference implementation” that does work, but is totally un-portable. An you’re a C# guy 😉

Ping-pong. Ping-pong.

A that times I always try to find the simplest common denominator, something that anyone can read and hopefully understand, for Web Services it is XML with SOAP message. Now you can send show it and tell: This is done according to the documentation, and does not work, can you look at this and tell me what’s wrong?

Then „they” can have a look and tell: …oh, you’ve got capitalization wrong, it’s not action it’s Action.

— VBS Script

strXML = "" & vbCRLF &_
"<soap:envelope>" & vbCRLF &_
" <soap:body>" & vbCRLF &_
" <sendsmsmessage>" & vbCRLF &_
" <content>Fooo Bar</content>" & vbCRLF &_
" <msisdn>5555555</msisdn>" & vbCRLF &_
" <account>John</account>" & vbCRLF &_
" </sendsmsmessage>" & vbCRLF &_
" </soap:body>" & vbCRLF &_
"</soap:envelope>" & vbCRLF</code>

wscript.echo strXML

Set oHttpReq = CreateObject( „MSXML2.ServerXMLHTTP” )
'oHttpReq.setTimeouts resolveTimeout, connectTimeout, sendTimeout, receiveTimeout
oHttpReq.setTimeouts 5*1000, 60*1000, 60*1000, 4*60*1000

oHttpReq.open „POST”, „http://foo.bar/context/services/service”, False, „username”, „password”
oHttpReq.setRequestHeader „Content-Type”, „text/xml”
oHttpReq.setRequestHeader „SOAPAction”, „action”
oHttpReq.send strXML

wscript.echo oHttpReq.status & ” ” & oHttpReq.statusText
'wscript.echo oHttpReq.responseText
wscript.echo oHttpReq.responseXML.xml

Dim objFileSystem, objOutputFile
Dim strOutputFile

Set objFileSystem = CreateObject(„Scripting.fileSystemObject”)
Set objOutputFile = objFileSystem.CreateTextFile(„out.txt”, TRUE)

objOutputFile.WriteLine(„— AllResponseHeaders —„)
objOutputFile.WriteLine(oHttpReq.getAllResponseHeaders)
objOutputFile.WriteLine(„— ResponseText —„)
objOutputFile.WriteLine(oHttpReq.responseText)
objOutputFile.WriteLine(„— ResponseXML —„)
objOutputFile.WriteLine(oHttpReq.responseXML.xml)
objOutputFile.Close
objOutputFile = Nothig

Set oHttpReq = Nothing
Set oXML = Nothing

Leave a Reply

Back to Top