For a project we need to call some webservices from vbscript. These webservices are protected using SSL (Server only authentication).
I know how to do this in C#, C++ (using gSoap), but this is first time for me in VBScript. A sample webservice is like:
matchUser (firstname, lastname, gender, dob)
Webservice will return true/false to denote success/failure of webservice call, moreover it will also have a response parameter isMatchFound to denote if a match was found.
As I am completely new with VBScript, I googled and wrote few line of code to start with:
Function sendRequestToServer(firstname, lastname, gender, dob)
Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP.3.0")
Set oXMLDoc = CreateObject("MSXML2.DOMDocument")
URL = https://www.samplewebServer.com:1122/matchAlert?wsdl
strEnvelope = "LastName=" & lastname & "FirstName=" & firstname & "Sex=" & gender & "BirthDate=" & dob
Msgbox("Calling WebServices URL " + URL + strEnvelope)
retryCount = 0
On Error Resume Next
Do
Err.Clear 'clear whatever error we had in the last iteration
retryCount = retryCount + 1
call oXMLHTTP.open("POST", URL, false)
call oXMLHTTP.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
call oXMLHTTP.send(strEnvelope)
dim szResponse: szResponse = oXMLHTTP.responseText
If Err Then WScript.Sleep 1000 'wait 1 seconds after an error occurred
Loop While Err and retryCount < 3
if (retryCount = 3 and Err.Number <> cstr(0)) then
MsgBox "Web Service is Down"
end if
call oXMLDoc.loadXML(szResponse)
if(oXMLDoc.parseError.errorCode <> 0) then
Msgbox("ERROR")
response = oXMLHTTP.responseText&" "&oXMLDoc.parseError.reason
Msgbox(oXMLDoc.parseError.reason)
else
response = oXMLDoc.getElementsByTagName("string")(0).childNodes(0).text
end if
End FunctionI have below doubts in the above code:
- How should I implement SSL server only authentication in above code?
- How should I call a particular web service from the above mentioned WSDL URL (i.e. matchUser())
- Is the way I am trying to pass parameters to matchUser() by building a string is correct? Or shall I build a XML string defining body of parameters?
- How should I check return value from matchUser() web service?
Any help would be appreciated, a sample code is highly desirable but some pointers on how to get started would also be very helpful.