Call a Web ServiceTag(s): WSH VBScript
We are calling the function put of a Web service.
This function takes 2 parameters: a string and a long.
' if the web services a user/pwd then you can try this :
' user = "myusername"
' pwd = "mypassword"
' strUrl = "http://" & user & ":" & pwd & "@server.company.local/ws/utility"
strUrl = "http://server.company.local/ws/utility"
strRequest = "<env:Envelope xmlns:env=""http://schemas.xmlsoap.org/soap/envelope/""" &_
" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""" &_
" xmlns:soapenc=""http://schemas.xmlsoap.org/soap/encoding/""" &_
" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">" &_
" <env:Header>" &_
" </env:Header>" &_
" <env:Body env:encodingStyle=""http://schemas.xmlsoap.org/soap/encoding/"">" &_
" <m:put xmlns:m=""http://company.local"" >" &_
" <string xsi:type=""xsd:string"">testing</string>" &_
" <longVal xsi:type=""xsd:long"">1000</longVal>" &_
"</m:put>" &_
"</env:Body>" &_
"</env:Envelope>"
dim http
set http=createObject("Microsoft.xmlhttp")
http.open "GET",strUrl,false
http.setRequestHeader "Content-Type","text/xml"
WScript.Echo "REQUEST : " & strRequest
http.send strRequest
If http.Status = 200 Then
WScript.Echo "RESPONSE : " & http.responseXML.xml
else
WScript.Echo "ERRCODE : " & http.status
End If
REQUEST :
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<env:Header> </env:Header>
<env:Body env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<m:put xmlns:m="http://company.local" >
<string xsi:type="xsd:string">testing</string>
<longVal xsi:type="xsd:long">1000</longVal>
</m:put>
</env:Body></env:Envelope>
RESPONSE :
<?xml version="1.0" standalone="yes"?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<env:Header></env:Header>
<env:Body env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<m:putResponse xmlns:m="http://company.local"></m:putResponse>
ok
</env:Body>
</env:Envelope>
To parse a response, you use the XPath parser.
This example calls a list function and the function returns a value in the body response.
strUrl = "http://server.company.local/ws/utility"
strRequest = "<env:Envelope xmlns:env=""http://schemas.xmlsoap.org/soap/envelope/""" &_
" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""" &_
" xmlns:soapenc=""http://schemas.xmlsoap.org/soap/encoding/""" &_
" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">" &_
" <env:Header>" &_
" </env:Header>" &_
" <env:Body env:encodingStyle=""http://schemas.xmlsoap.org/soap/encoding/"">" &_
" <m:list xmlns:m=""http://company.local""> " &_
" </m:list>" &_
" </env:Body>" &_
" </env:Envelope>"
Dim http
Set http=CreateObject("Microsoft.xmlhttp")
http.Open "GET",strUrl,false
http.SetRequestHeader "Content-Type","text/xml"
WScript.Echo "REQUEST :" & strRequest
http.Send strRequest
If http.Status = 200 Then
WScript.Echo "RESPONSE :" & http.responseXML.xml
Set xmlDoc = CreateObject("Microsoft.XMLDOM") 'CreateObject("MSXML2.DOMDocument")
xmlDoc.SetProperty "ServerHTTPRequest", False
xmlDoc.setProperty "SelectionLanguage", "XPath"
xmlDoc.setProperty "SelectionNamespaces", "xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'"
xmlDoc.async = False
xmlDoc.loadXML(http.responseXML.xml)
For Each x In xmlDoc.documentElement.childNodes
WScript.Echo x.nodename & ": " & x.text
Next
set strResponse = xmlDoc.documentElement.selectSingleNode("//env:Body")
WScript.Echo
WScript.Echo "** RESPONSE : " & strResponse.text
Else
WScript.Echo "ERRCODE : " & http.status
End If
REQUEST :
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<env:Header> </env:Header>
<env:Body env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<m:list xmlns:m="http://intranet-ac.ssq.local"> </m:list>
</env:Body> </env:Envelope>
RESPONSE :
<?xml version="1.0" standalone="yes"?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<env:Header></env:Header>
<env:Body env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<m:listResponse xmlns:m="http://saac.ssq.local/commun">
<result xsi:type="xsd:string">\\company.local\fonc_sas, \\company.local\unit_sas, \\company.local\prod_sas</result>
</m:listResponse>
</env:Body></env:Envelope>
env:Header:
env:Body: \\company.local\fonc_sas, \\company.local\unit_sas, \\company.local\prod_sas
** RESPONSE :
\\company.local\fonc_sas, \\company.local\unit_sas, \\company.local\prod_sas
mail_outline
Send comment, question or suggestion to howto@rgagnon.com
Send comment, question or suggestion to howto@rgagnon.com