Friday 7 April 2017

How to a call a soap web service from VB6

Private Sub Command3_Click()
''Define our WebService constants
Const WebService_ServerURL = "http://localhost:59629/XXXXXXXasmx"

Const WebService_NameSpace = "http://tempuri.org"

''Declare the objects (Early Binding)
Dim Envelope As PocketSOAP.CoEnvelope
Dim Transport As winhttp.WinHttpRequest

''Instantiate the Objects
Set Envelope = New PocketSOAP.CoEnvelope12
Set Transport = New winhttp.WinHttpRequest


Dim PXML As String

PXML = "<Root></Root>"
''Set the methodName and methodname Namespace values
Envelope.SetMethod "Request", "http://tempuri.org/"
Envelope.Parameters.Create "strRequest", PXML, "http://tempuri.org/"
''Define the parameters

''Initialize WinHTTP
Transport.Open "POST", WebService_ServerURL, False
'' Set Request Headers
Transport.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
Transport.setRequestHeader "SOAPAction", WebService_NameSpace & "/" & Envelope.MethodName

'e.SetMethod "query", ns
'e.Parameters.Create "query", "select Id, name from account order by systemModStamp desc limit 5", ns





' Transport.SetClientCertificate()



'' Send the serialized SOAP request
'' This is where the actual data is transmitted, and the response is received.
'' This may take a little while to return.
Transport.send Envelope.Serialize


'' Parse the response, and display the result
Envelope.Parse Transport.responseText
MsgBox Transport.responseText

End Sub