By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,682 Members | 1,065 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,682 IT Pros & Developers. It's quick & easy.

Problem with Async WS

P: n/a
Ken
I have an async Web service working inside a Try block just like MS says

Try
Dim cb As New AsyncCallback(AddressOf callbackWs)
myWS.BeginUpdater("StringChain", cb, myWS)
Catch x As Exception
MessageBox.Show("Something happened")
End Try

the Callback routine

Sub callbackWs(ByVal ar As IAsyncResult)
Try
myWS = ar.AsyncState
Dim a As String = myWS.EndUpdater(ar)
MessageBox.Show(a)
Catch x As Exception
MessageBox.Show("Something happened")
End Try
End Sub

If for any reason is impossible to reach the WS the program does not enter
into the Catch block. It does nothing so how can I alert the user that is not
connection to the WS?

ken

Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Ken" <Ke*@discussions.microsoft.com> wrote in message news:EE**********************************@microsof t.com...
I have an async Web service working inside a Try block just like MS says : : If for any reason is impossible to reach the WS the program does not enter
into the Catch block. It does nothing so how can I alert the user that is not
connection to the WS?


You need to set a time out beyond which you aren't going to wait any longer
and assume the worst. Don't lose the handle to the IAsyncResult that Begin-
Updater( ) returned to you,

Dim updaterResult As IAsyncResult
' . . .
updaterResult = myWS.BeginUpdater( "StringChain", cb, myWS)

Now, if you're willing to sit around and wait, or spawn another worker
thread to wait for you ;-) then you can use the WaitHandle of the IAsyncResult
and give it a time out period that you're willing to wait for the web service to
return,

' Wait up to 15 seconds for Updater web service to complete,
' if it's not done by then WaitOne returns False and I terminate
' the request.
'
If Not updaterResult.AsyncWaitHandle.WaitOne( 15000, True) Then
myWS.Abort
End If

If the Updater web service hasn't completed within fifteen seconds then the worker
thread is aborted (note that you'll then get called on your callback, if any, for a
SOAP fault indicating the connection was closed [by you]).

This sort of gets away from why you wanted an asynchronous call in the first
place, unless you put this into a second "watchdog" thread whose only purpose
is to wait for the web service response, and end matters if they take too long.

The other thing to do is to wire yourself to a Timer and have the Timer call you
back in 15 seconds (or whatever period of latency you're willing to tolerate) so
you can check the AsyncWaitHandle to see if the work has finished.

In either case these timeout techniques involve three threads (the main thread,
the web request worker thread, and a watchdog worker thread to timeout).
Derek Harmon
Nov 21 '05 #2

P: n/a
Ken
thanks..

"Derek Harmon" wrote:
"Ken" <Ke*@discussions.microsoft.com> wrote in message news:EE**********************************@microsof t.com...
I have an async Web service working inside a Try block just like MS says

: :
If for any reason is impossible to reach the WS the program does not enter
into the Catch block. It does nothing so how can I alert the user that is not
connection to the WS?


You need to set a time out beyond which you aren't going to wait any longer
and assume the worst. Don't lose the handle to the IAsyncResult that Begin-
Updater( ) returned to you,

Dim updaterResult As IAsyncResult
' . . .
updaterResult = myWS.BeginUpdater( "StringChain", cb, myWS)

Now, if you're willing to sit around and wait, or spawn another worker
thread to wait for you ;-) then you can use the WaitHandle of the IAsyncResult
and give it a time out period that you're willing to wait for the web service to
return,

' Wait up to 15 seconds for Updater web service to complete,
' if it's not done by then WaitOne returns False and I terminate
' the request.
'
If Not updaterResult.AsyncWaitHandle.WaitOne( 15000, True) Then
myWS.Abort
End If

If the Updater web service hasn't completed within fifteen seconds then the worker
thread is aborted (note that you'll then get called on your callback, if any, for a
SOAP fault indicating the connection was closed [by you]).

This sort of gets away from why you wanted an asynchronous call in the first
place, unless you put this into a second "watchdog" thread whose only purpose
is to wait for the web service response, and end matters if they take too long.

The other thing to do is to wire yourself to a Timer and have the Timer call you
back in 15 seconds (or whatever period of latency you're willing to tolerate) so
you can check the AsyncWaitHandle to see if the work has finished.

In either case these timeout techniques involve three threads (the main thread,
the web request worker thread, and a watchdog worker thread to timeout).
Derek Harmon

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.