Calling Web Service using VB6 without SOAP
-
Iam using HTTP to call web service without SOAP. It gives Error: 500" Please anyone tell whats the error. Actually its status is not 200. Is there any other method to call webservice using vb6 without SOAP? Here is my code below: Public Function Run_WebService(ByRef InForm As Form, ByVal CaseNo As Integer) As Boolean On Error GoTo Catch Dim IsOk As Boolean Dim StrResults As String Dim ObjXMLHTTP As Object Dim ObjXMLDOM As Object Const WebSite As String = "http://localhost/MyService/MyWebService.asmx/" Dim iPos As Long, jPos As Long Dim MakeParameters As String IsOk = False Set ObjXMLHTTP = CreateObject("Microsoft.XMLHTTP") Set ObjXMLDOM = CreateObject("Microsoft.XMLDOM") Select Case CaseNo Case 1 With ObjXMLHTTP .Open "GET", WebSite & "MyProduct?ID=5" , False ', "sa", "password" .Send DoEvents If .Status = 200 Then 'is ok 'Load the XML document from the webservice ObjXMLDOM.loadXML .ResponseText 'check if there are any errors If ObjXMLDOM.parseError.ErrorCode <> 0 Then MsgBox .ResponseText IsOk = False Else 'Get the results StrResults = ObjXMLDOM.GetElementsByTagName("string").Item(0).Text 'iPos = InStr(1, StrResults, "<code>", vbTextCompare) 'iPos = iPos + Len("<code>") 'jPos = InStr(1, StrResults, "</code>", vbTextCompare) 'If Val(jPos) = 0 Then ' StrResults = "Invalid Country." 'Else ' StrResults = Mid$(StrResults, iPos, jPos - iPos) 'End If 'InForm.txtResults(0).Text = StrResults IsOk = True End If Else MsgBox "ERROR - " & .Status, vbCritical, "ERROR" IsOk = False End If End With End Select ExitFunction: Set ObjXMLHTTP = Nothing Set ObjXMLDOM = Nothing StrResults = vbNullString Run_WebService
-
Iam using HTTP to call web service without SOAP. It gives Error: 500" Please anyone tell whats the error. Actually its status is not 200. Is there any other method to call webservice using vb6 without SOAP? Here is my code below: Public Function Run_WebService(ByRef InForm As Form, ByVal CaseNo As Integer) As Boolean On Error GoTo Catch Dim IsOk As Boolean Dim StrResults As String Dim ObjXMLHTTP As Object Dim ObjXMLDOM As Object Const WebSite As String = "http://localhost/MyService/MyWebService.asmx/" Dim iPos As Long, jPos As Long Dim MakeParameters As String IsOk = False Set ObjXMLHTTP = CreateObject("Microsoft.XMLHTTP") Set ObjXMLDOM = CreateObject("Microsoft.XMLDOM") Select Case CaseNo Case 1 With ObjXMLHTTP .Open "GET", WebSite & "MyProduct?ID=5" , False ', "sa", "password" .Send DoEvents If .Status = 200 Then 'is ok 'Load the XML document from the webservice ObjXMLDOM.loadXML .ResponseText 'check if there are any errors If ObjXMLDOM.parseError.ErrorCode <> 0 Then MsgBox .ResponseText IsOk = False Else 'Get the results StrResults = ObjXMLDOM.GetElementsByTagName("string").Item(0).Text 'iPos = InStr(1, StrResults, "<code>", vbTextCompare) 'iPos = iPos + Len("<code>") 'jPos = InStr(1, StrResults, "</code>", vbTextCompare) 'If Val(jPos) = 0 Then ' StrResults = "Invalid Country." 'Else ' StrResults = Mid$(StrResults, iPos, jPos - iPos) 'End If 'InForm.txtResults(0).Text = StrResults IsOk = True End If Else MsgBox "ERROR - " & .Status, vbCritical, "ERROR" IsOk = False End If End With End Select ExitFunction: Set ObjXMLHTTP = Nothing Set ObjXMLDOM = Nothing StrResults = vbNullString Run_WebService
Calling a Web Service using VB6 with SOAP 3.0[^] Calling Web Services from Visual Basic 6, the Easy Way[^] Or you could build the HTTP request string yourself, then parse the response yourself, though this is FAR from being a trivial task.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007