Question Asynchronous Webservice methods

gchq

Well-known member
Joined
Dec 14, 2007
Messages
168
Programming Experience
10+
Hi there

I have a Webservice and a widows client app developed in VS2005 on .NET 2.0. I am attempting to find a sample of a asycnchronous method of connecting to that webservice and return a DataSet in the background! Despite the fact that MS in their infinite wisdom abandoned the Begin and and End methods with VS2005 and replaced them with the Async and Completed methods most documentation STILL refers to the old methods and nearly all the sample code is in C# that doesn't seem to translate to VB at all....

If anyone knows of a good VB.Net source, or can offer some basic help on the syntax I would be very grateful - it's driving me up the wall....


The basic call is :-

Dim vService as New WebServ.WebServWSE
Dim DS as DataSet = vService.ReturnDateSet(strSQL, ClientID)
 
Sorted

In case anyone else has spent a couple of days banging their head over this one - or in case I've done something really daft and that is spotted, here is how I got this working.... I know the AddHandler is a bit redundant since the service was defined WithEvents... but if it's not broken 'n' all that...


VB.NET:
Imports HOA2_Client.WebServTest
Module DBDownloaded
    Private CurrentTable As String
    Public NL_Codes As DataTable
    Public Customers As DataTable
    Private WithEvents vService As WebServTest.WebServiceTestWse
    Private Sub DownloadStart(ByVal strSQL As String)
        Dim vService As New WebServTest.WebServiceTestWse
        AddHandler vService.ReturnDataSetCompleted, AddressOf ReturnDataSetCompleted
        vService.ReturnDataSetAsync(strSQL, Form1.vCurrentHOA)
    End Sub

    Private Sub ReturnDataSetCompleted(ByVal sender As Object, ByVal e As ReturnDataSetCompletedEventArgs) Handles vService.ReturnDataSetCompleted
        If Not e.Cancelled Then
            Dim DS As DataSet = e.Result
            Select Case CurrentTable
                Case "NL_Codes"
                    NL_Codes = New DataTable
                    NL_Codes = DS.Tables(0)
            End Select
        End If
    End Sub

    Public Sub ReturnNewDataSet(ByVal TableName As String)
        CurrentTable = TableName
        Dim strSQL As String = "SELECT * FROM " & TableName
        DownloadStart(strSQL)
    End Sub
End Module
 
Just stating the obvious, if you have the event with the Handles statement you don't need the Addhandler statement.
 
Back
Top