How to use asynchronous mode of web service in asp.net page?


N

Neo

Hi,

I use asynchronous mode of web service in asp.net page and specify a callback function.
My question is how can I keep the returned value ? It is not use that I added the returned value to session.

Thanks

The following is part of my codes.

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
Dim rMessage As New messagepublisher.UpdateMessage
Dim cb As AsyncCallback
cb = New AsyncCallback(AddressOf Me.GetMessage)

Dim ar As IAsyncResult = rMessage.BeginReceieveMessage(cb, rMessage)
Else
Response.Write(Session("ok"))
End If
End Sub

Private Sub GetMessage(ByVal ar As IAsyncResult)
Dim rMessage As MessagePublisher.UpdateMessage = ar.AsyncState
Dim m As string= rMessage.EndReceieveMessage(ar)
Session("ok") = m 'This is not working. This line is executed ,but I can not get the value of session("ok") when postback.
End Sub
 
Ad

Advertisements

D

Dale

Either use the asynchronous mode really really fast..... or not at all since
once the page has completed loading there is no way to send the value to the
page.

You can, of course, use the WaitOne, WaitAny, or WaitAll methods of the
IAsyncResult but then you're really becoming synchronous again, rather than
asynchrynous. The only advantage is that you could call the web service
method, finish up a bunch of other stuff in the mean time, and then wait.
That's as close as you're going to get to asynchrounous results in an
ASP.NET page.

Dale

Hi,

I use asynchronous mode of web service in asp.net page and specify a
callback function.
My question is how can I keep the returned value ? It is not use that
I added the returned value to session.

Thanks

The following is part of my codes.

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
Dim rMessage As New messagepublisher.UpdateMessage
Dim cb As AsyncCallback
cb = New AsyncCallback(AddressOf Me.GetMessage)

Dim ar As IAsyncResult = rMessage.BeginReceieveMessage(cb,
rMessage)
Else
Response.Write(Session("ok"))
End If
End Sub

Private Sub GetMessage(ByVal ar As IAsyncResult)
Dim rMessage As MessagePublisher.UpdateMessage = ar.AsyncState
Dim m As string= rMessage.EndReceieveMessage(ar)
Session("ok") = m 'This is not working. This line is executed ,but
I can not get the value of session("ok") when postback.
End Sub
 
Ad

Advertisements

S

Steve Letford

You could run it off on another thread that stores its result in session
value when its finished.
set some meta tags to refresh the page every five seconds displaying that
you are processing to the user.

Then when the thread has finished processing and stored the correct result
display it to the user and remove the refresh meta tags. There are lots of
examples on the web about multi threading a web app.

hope this helps
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top