Skip to content

Instantly share code, notes, and snippets.

@eddy8
Created May 23, 2014 08:09
Show Gist options
  • Save eddy8/c8d1d4df0a2c15ad66a7 to your computer and use it in GitHub Desktop.
Save eddy8/c8d1d4df0a2c15ad66a7 to your computer and use it in GitHub Desktop.
vb6 use java webservice with post and soap
Private Sub Command1_Click()
Dim strSoapAction As String
Dim strUrl As String
Dim strxml As String
Dim returnMsg As String
strUrl = "http://xxx.com/xxx"
strSoapAction = "http://yyy.com/zzz"
strxml = "<?xml version=""1.0"" encoding=""GBK""?>" & _
"<soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">" & _
"<soap:Body><send xmlns=""http://www.jwstest.org"">" & "your xml message string" & "</soap:Body></soap:Envelope>"
returnMsg = PostWebservice(strUrl, strSoapAction, strxml)
End Sub
Private Function PostWebservice(ByVal AsmxUrl As String, ByVal SoapActionUrl As String, ByVal XmlBody As String) As String
Dim objDom As Object
Dim objXmlHttp As Object
Dim strRet As String
Dim intPos1 As Integer
Dim intPos2 As Integer
On Error GoTo Err_ED
Set objDom = CreateObject("MSXML2.DOMDocument")
Set objXmlHttp = CreateObject("MSXML2.XMLHTTP")
objDom.async = False
objDom.LoadXml XmlBody
objXmlHttp.Open "POST", AsmxUrl, False
objXmlHttp.setRequestHeader "Content-Type", "text/xml; charset=gbk"
objXmlHttp.setRequestHeader "SOAPAction", SoapActionUrl
objXmlHttp.setRequestHeader "Content-Length", Len(XmlBody)
objXmlHttp.send objDom.xml
strRet = objXmlHttp.responseText
Set objXmlHttp = Nothing
PostWebservice = strRet
Exit Function
Err_ED:
PostWebservice = "Error: " & Err.Number & " - " & Err.Description
End Function
Private Sub Command2_Click()
Dim client As New SoapClient30
Dim str As String, strxml As String
strxml = "your xml message string"
client.MSSoapInit "http://xxx.com/xxx?wsdl"
str = client.methodName(strxml)
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment