Results 1 to 2 of 2

Thread: Client Asynchronous WebService call issue

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2001
    Location
    Washington, USA
    Posts
    61

    Client Asynchronous WebService call issue

    I'm trying to perform an Asynchronous call to a web service. The web service itself is a simple query, that returns a dataset, such as:

    <WebMethod()> Public Function RetrieveSQL(ByVal sql As String) As DataSet
    Dim cs As String = "data source=localhost;"
    Dim cn As New System.Data.SqlClient.SqlConnection(cs)
    Dim da As New System.Data.SqlClient.SqlDataAdapter(sql, cn)
    Dim ds As New System.Data.DataSet()
    da.Fill(ds)
    Return ds
    End Function

    The client calls the web service, via two methods. One is Asynchronous, the other is Synchronous:

    'TextBox1.Text contains the SQL statement to call

    Private Sub AsyncCall_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AsyncCall.Click
    Dim ws As New localhost.Service1()
    Dim cb As AsyncCallback = New AsyncCallback(AddressOf EndRetrieveSQL)
    ws.BeginRetrieveSQL(TextBox1.Text, cb, ws)
    End Sub

    Private Sub EndRetrieveSQL(ByVal ar As System.IAsyncResult)
    Dim ws As localhost.Service1 = ar.AsyncState
    Dim ds As DataSet = ws.EndRetrieveSQL(ar)
    DataGrid1.DataSource = ds.Tables(0)
    End Sub

    Private Sub SyncCall_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SyncCall.Click
    Dim ws As New localhost.Service1()
    Dim ds As DataSet = ws.RetrieveSQL(TextBox1.Text)
    DataGrid1.DataSource = ds.Tables(0)
    End Sub

    When I call it with the SyncCall button click, it returns the full dataset.
    When I call it with the AsyncCall button click, it returns an empty dataset.

    In the EndRetrieveSQL subroutine on the client, the first line
    Dim ws As localhost.Service1 = ar.AsyncState
    is wrong.
    I know that the error to my code is in the client callback subroutine EndRetrieveSQL. How do I get this to work?

    Samwise

  2. #2

    Thread Starter
    Member
    Join Date
    Jan 2001
    Location
    Washington, USA
    Posts
    61
    OK, update.
    After more extensive testing, I found out that the Asynchronous calls and the Synchronous calls are returning the same dataset.
    The number of columns and rows match correctly.
    (I verified it by dumping the contents of the returned DataTable from the DataSet into the Console window)

    The problem occurs when I perform setting the DataSource of the DataGrid to it's appropriate DataTable. Then, the problem occurs.

    In the Synchronous case, the DataGrid shows all of the data correctly.

    In the Asynchronous case, the DataGrid shows the correct number of rows, the correct width and height, but no data.

    So why is it when the Asynchronous call occurs, it creates a faulty DataBind while the Synchronous call occurs, it is OK?

    Samwise

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width