Articles → VBA FOR EXCEL → Call web service in VBA

Call web service in VBA






Sample web service







Adding reference







Click to Enlarge




Click to Enlarge


Code




Dim sMsg As String
Dim sURL As String
Dim sEnv As String

Set ObjHTTP = New MSXML2.XMLHTTP
sURL = "http://www.dneonline.com/calculator.asmx?op=Add"
sEnv = "<?xml version=""1.0"" encoding=""utf-8""?>"
sEnv = sEnv & "<soap12:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap12=""http://www.w3.org/2003/05/soap-envelope"">"
sEnv = sEnv & "<soap12:Body>"
sEnv = sEnv & "<Add xmlns=""http://tempuri.org/"">"
sEnv = sEnv & "<intA>1</intA>"
sEnv = sEnv & "<intB>2</intB>"
sEnv = sEnv & "</Add>"
sEnv = sEnv & "</soap12:Body>"
sEnv = sEnv & "</soap12:Envelope>"

ObjHTTP.Open "Post", sURL, False
ObjHTTP.setRequestHeader "Content-Type", "text/xml"
ObjHTTP.setRequestHeader "Action", "http://tempuri.org/Add"

ObjHTTP.Send (sEnv)
MsgBox ObjHTTP.responseText

Set ObjHTTP = Nothing
Set xmlDoc = Nothing



Output



Click to Enlarge

Posted By  -  Karan Gupta
 
Posted On  -  Sunday, October 21, 2018

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250