Wednesday, January 11, 2012

VBScript - Send SOAP packet to call a webservice using http post

Please copy and paste in ur projecy, the below code snippet works fine for posting soap packet using http post to a web service


<script type="text/vbscript">

document.write("Hello World from VB Script")

Dim strSoapReq
strSoapReq = "<s12:Envelope xmlns:s12='http://www.w3.org/2003/05/soap-envelope'>"
strSoapReq = strSoapReq +   "<s12:Body>"
strSoapReq = strSoapReq +   "<ns1:GetCitiesByCountry xmlns:ns1='http://www.webserviceX.NET'>"      
strSoapReq = strSoapReq +   "<ns1:CountryName xmlns:ns1='http://www.webserviceX.NET'>Pakistan</ns1:CountryName>"    
strSoapReq = strSoapReq +   "</ns1:GetCitiesByCountry>"
strSoapReq = strSoapReq +    "</s12:Body>"
strSoapReq = strSoapReq +    "</s12:Envelope>"      

Dim oHttp
Dim strResult
Set oHttp = CreateObject("Msxml2.XMLHTTP")
oHttp.open "POST", "http://www.webservicex.com/globalweather.asmx", false
oHttp.setRequestHeader "Content-Type", "application/soap+xml; charset=utf-8"
oHttp.setRequestHeader "Content-Encoding", "UTF-8"
oHttp.setRequestHeader "SOAPAction", "http://www.webserviceX.NET/GetCitiesByCountry"
oHttp.setRequestHeader "Host" , "www.webservicex.com"
oHttp.setRequestHeader "Content-Length", Len(strSoapReq)
oHttp.send strSoapReq
strResult = oHttp.responseText
document.write(strResult)
MsgBox strResult
  
</script>

1 comment: