Sunday, December 27, 2009

Invoke .NET web service from VB6

There are a lot of projects which currently run in VB6 but in an unwilling situation to migrate it to the new version of VB.NET or C#. In one such situation, it was decided to continue using VB6 application with validation done using Web Service created in .NET

I am just including a sample code for writing the same :

VB6 Code :

Dim iFirst As Integer
Dim iSecond As Integer

Dim bNothing As Boolean

Dim MSSCWebSrvc As New MSSOAPLib.SoapClient

Dim objRS As New ADODB.Recordset

On Error Resume Next

'-- Virtual Directory
MSSCWebSrvc.mssoapinit ("http://localhost/test/VBWebService.asmx?wsdl")

If Err.Number = -2147024809 Then
MsgBox "Invalid WebService Request. Please check the URL"
End If

iFirst = 10
iSecond = 5
bNothing = False

'Invoking the AddData method in web service to add the two values.
MsgBox ("Total is : " & MSSCWebSrvc.AddData(iFirst, iSecond))

'To deal with DataSets/Recordsets we can try the following code.

Set objRS = MSSCWebSrvc.objRSReturn()
If objRS.EOF Then
MsgBox " no records "
Else
MsgBox " records found... "
End If

I hope this helps.

No comments:

Post a Comment