-
VBScript SOAP
Does anyone have a good example for sending a SOAP authentication request from a VBScript?
Any help would be appreciated,
Dan
I’ve got it working, here’s the code if anyone needs it. hope it helps someone else.
Code:
Function ZimbraAuthentication()
'////Zimbra authentication function
Dim SOAPRes, Temp, SOAPMessage, AdminUserName, AdminPassword, http
Const SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS = 13056
Const SoapServer = "https://Server:7071/service/admin/soap"
'////Domain admin account on Zimbra server
AdminUserName = "Admin@zimbratest.mccneb.edu"
AdminPassword = "Password"
'////Zimbra SOAP Authrequest
SOAPMessage = "<soap:Envelope xmlns:soap="&chr(34)&"http://www.w3.org/2003/05/soap-envelope"&chr(34)&">" & _
"<soap:Header>" & _
" <context xmlns="&chr(34)&"urn:zimbra"&chr(34)&">" & _
"<nosession/>" & _
"</context>" & _
"</soap:Header>" & _
"<soap:Body>" & _
"<AuthRequest xmlns="&chr(34)&"urn:zimbraAdmin"&chr(34)&">" & _
"<name> "& AdminUserName &"</name>" & _
"<password>"& AdminPassword &"</password>" & _
"</AuthRequest>" & _
"</soap:Body>" & _
"</soap:Envelope>"
'////Start setting up the SOAP packet & Set it to ignore all cert errors (if self-signed cert)
Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.setOption 2, SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS
xmlhttp.open "POST", SoapServer, False
xmlhttp.setRequestHeader "Man", POST & " " & SoapServer & " HTTP/1.1"
xmlhttp.setRequestHeader "MessageType", "CALL"
xmlhttp.setRequestHeader "Content-Type", "text/xml"
xmlhttp.send(SoapMessage)
'////For Testing
WScript.Echo xmlhttp.status
WScript.Echo xmlhttp.statusText
WScript.Echo xmlhttp.responseText
'////Get the authToken from the zimbra SOAP response to pass to other functions
SOAPRes = Split(xmlhttp.responseText, "<")
Temp = Split(SOAPRes(9), ">")
ZimbraAuthentication = Temp(1)
End Function