Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

calling webservice asynchronously in vb.net

I am trying to call this webservice asynchrounously in vb.net. So on the aspx side i added this property async="true". Now on the vb.net code side i have this function inside my webservice that i am calling. So -

dim as as webservice.webstring
as.functionasync(param1, param2)

Now when i run the page, i can see that it wont call the webservice after a timegap. Should i add .thread.sleep()? Do i require the beginAsyn function and the EndAsyn function. I'm using asp.net 3.5 with IIS7

like image 498
powel Avatar asked Aug 09 '26 03:08

powel


1 Answers

First, please read this MSDN article about how the asynchronous pages work in ASP.NET.

Second, you need to have an asynchronous method in your web-service. Please read this HOWTO article about how to create such methods.

This is how your implementation of the async page could look like:

private _as as WebService.WebString = Nothing

Public Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
    AddOnPreRenderCompleteAsync(New BeginEventHandler(BeginCallingWebService),
        New EndEventHandler(EndCallingWebService));
End Sub

Private Function BeginCallingWebService(Byval sender As Object, ByVal e As EventArgs, ByVal cb As AsyncCallback, ByVal state As Object)
    _as = New WebService.WebString()

    Return _as.BeginMyMethod(cb, state)
End Function

Private Sub EndCallingWebService(ByVal ar as IAsyncResult)
    Dim result As MyWebServiceResult = _as.EndMyMethod(ar)

    ' Process the result of the web-service method
End Sub

Hope this will help you.

like image 88
volpav Avatar answered Aug 11 '26 12:08

volpav



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!