Developer Resources’s Weblog

June 13, 2008

VB/VBA Call WebService

Filed under: Web Services — Tags: , , — developerresources @ 8:11 pm

You can call a webservice from VBA simply by posting the soap envelope. Here is an example:

    Dim http As New WinHttp.WinHttpRequest
    Dim URL As String
    Dim envelope As String
    URL = "http://notificationserver/NotificationServer/NotifyService"
    envelope = "<?xml version=""1.0"" encoding=""UTF-8""?><soap:Envelope soap:encodingStyle=""http://schemas.xmlsoap.org/soap/encoding/"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:soapenc=""http://schemas.xmlsoap.org/soap/encoding/"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:tns=""http://NotificationServer.nvidia.com/""><soap:Body><tns:notify><id xsi:type=""xsd:string"">blah</id><from xsi:type=""xsd:string"">from </from><subject xsi:type=""xsd:string"">subject</subject><details xsi:type=""xsd:string"">details</details></tns:notify></soap:Body></soap:Envelope>"

    Call http.Open("POST", URL)

    http.SetRequestHeader "Content-Type", "text/xml"
    http.SetRequestHeader "SOAPAction", " "

    http.Send envelope
    MsgBox http.ResponseText

1 Comment »

  1. Hi,

    What if you need to send some binary data to the web service as well? I guess the code above would not work… any example on how do to that?

    Thanks,
    Luiz

    Comment by Luiz — January 23, 2009 @ 5:10 pm


RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.