I'm trying to send a request to a web service for our accounting software using VBA in Excel. The HTTP request is new to me, but the VBA part is not. Any help would be greatly appreciated, especially explanations on how this process works. I'd like to understand it, but so far everything I have found has not worked and has just made me more confused.
I've done some research and tried to figure this out myself, and I've made some progress. Now I'm just hitting a wall with how and/or where to send the request.
The technical documentation gives me method names and WSDL locations, and I've gotten the WSDL for the GET method I'm trying to use. I used SOAPUI to build a SOAP Envelope based on the WSDL.
My (censored) VBA code is below:
I've done some research and tried to figure this out myself, and I've made some progress. Now I'm just hitting a wall with how and/or where to send the request.
The technical documentation gives me method names and WSDL locations, and I've gotten the WSDL for the GET method I'm trying to use. I used SOAPUI to build a SOAP Envelope based on the WSDL.
My (censored) VBA code is below:
Whenever I run this, all I get back is html that produces a table with Endpoint and WSDL links for the method. There's no xml SOAP response, which is what I'm expecting back. Am I sending this to the wrong URL or something? Is my request header not right?Quote:
Sub GetJobTest()
Dim strURL As String
Dim strWSDLURL As String
Dim strEnv As String
Dim objHTTP As New MSXML2.XMLHTTP60
Dim objXMLDoc As New MSXML2.DOMDocument60
Dim xmlReturnArray As MSXML2.IXMLDOMNode
Dim xmlReturnElement As MSXML2.IXMLDOMNode
guid = CreateGuidString() 'Creates a GUID using a function that isn't shown
strURL = "https://ourserver.com:####/ws/GetJob"
strWSDLURL = "https://ourserver.com:####/ws/GetJob"
strResult = ""
'Build SOAP envelope
strEnv = "<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:typ=""http://www.northgate-is.com/proiv/webservices/types"">" _
& "<soapenv:Header/>" _
& "<soapenv:Body>" _
& "<typ:GetJob>" _
'Stuff goes here'
& "</typ:GetJob>" _
& "</soapenv:Body>" _
& "</soapenv:Envelope>" _
'Debug.Print strEnv
With objHTTP
.Open "GET", strWSDLURL, False 'Open HTTP object connection
.setRequestHeader "Content-Type", "text/xml;charset=UTF-8" 'Set request header content type
.setRequestHeader "soapAction", strURL 'Set SOAP action of request header
.setRequestHeader "Accept-encoding", "gzip,deflate" 'Set request header encoding
.setRequestHeader "Connection", "Keep-Alive" 'This does something
.send strEnv 'Send Request with SOAP envelope
End With
objXMLDoc.LoadXML (objHTTP.responseText)
Debug.Print objHTTP.responseText 'print the response
Set objHTTP = Nothing
Set objXMLDoc = Nothing
End Sub