'How write Visual Basic code for SOAP request?
I can't find out the solution of a very hard issue - for me :)
I'm trying to "simulate" a call request - usually I do it in SOAP UI - inside a Visual Basic script.
Let me explain better.
I have an application (One Identity) that use some scripts (written in visual basic) in order to "communicate" with other applications. These target applications have some SOAP API available for our scope, in fact I can do manually a certain request via SOAP UI: for example I can query all the users present in the target application, create a new user and so on. Hence, I copy the proper xml in the request window of SOAP UI, lunch the application and I'll get back the xml response.
My goal is to avoid using SOAP UI because I want automatize the process: I have to write some visual basic code, and trigger it when we need it.
My question: how can I write a visual basic code that allows me to ask SOAP UI: here is the xml request, lunch it in the target application? I didn't find a working example or something that I can re-use. Moreover the communication occur over a SSL connection, so I need to load the certificate.
Hope I was clear. Anyone has some templates, tips or useful links?
Thanks a lot for you help!
Solution 1:[1]
This is sample code for SOAP opp, you must provide your url , and correct the XML as needed . You must reference Microsoft XML, v 3.0
Public Sub PingRN()
Dim xmlHtp As New MSXML2.XMLHTTP
Dim sURL As String
Dim sEnv As String
Dim XMLDOC As New DOMDocument
' change the following URL to yours
sURL = "https://somesite.com/cgi-bin/services/soap"
sEnv = "<?xml version=" & Chr(34) & "1.0" & Chr(34) & " encoding=" & Chr(34) & "UTF-8" & Chr(34) & "?>"
sEnv = sEnv & "<soap:Envelope xmlns:xsi=" & Chr(34) & "http://www.w3.org/2001/XMLSchema-instance" & Chr(34) & " xmlns:xsd=" & Chr(34) & "http://www.w3.org/2001/XMLSchema" & Chr(34) & " xmlns:soap=" & Chr(34) & "http://schemas.xmlsoap.org/soap/envelope/" & Chr(34) & ">"
sEnv = sEnv & "<soap:Header>"
sEnv = sEnv & "<ns6:ClientInfoHeader xmlns:ns6=" & Chr(34) & "urn:messages.ws.rightnow.com/v1_2" & Chr(34) & ">"
sEnv = sEnv & "<ns6:AppID>Basic Query Test</ns6:AppID>"
sEnv = sEnv & "</ns6:ClientInfoHeader>"
sEnv = sEnv & "<wsse:Security xmlns:wsse=" & Chr(34) & "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" & Chr(34) & ">"
sEnv = sEnv & "<wsse:UsernameToken>"
' the following user name and pw were changed, please change to yours
sEnv = sEnv & "<wsse:Username>xyz</wsse:Username>"
sEnv = sEnv & "<wsse:Password>!t3$T</wsse:Password>"
sEnv = sEnv & "</wsse:UsernameToken>"
sEnv = sEnv & "</wsse:Security>"
sEnv = sEnv & "</soap:Header>"
sEnv = sEnv & "<soap:Body>"
sEnv = sEnv & "<ns7:QueryCSV xmlns:ns7=" & Chr(34) & "urn:messages.ws.rightnow.com/v1_2" & Chr(34) & ">"
sEnv = sEnv & "<ns7:Query>SELECT C.Name.First, C.Name.Last, C.CustomFields.c.SSC FROM Contact C WHERE C.Login = 'D01301061';</ns7:Query>"
sEnv = sEnv & "<ns7:PageSize>1000</ns7:PageSize>"
sEnv = sEnv & "</ns7:QueryCSV>"
sEnv = sEnv & "</soap:Body>"
sEnv = sEnv & "</soap:Envelope>"
With xmlHtp
.Open "POST", sURL, False
.setRequestHeader "Host", ""
.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
.setRequestHeader "soapAction", "QueryCSV" ' per the documentation
.send sEnv
XMLDOC.LoadXML .responseText
XMLDOC.Save ActiveWorkbook.Path & "\WebQueryResult2.xml"
End With
MsgBox xmlHtp.statusText
End Sub
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
