Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / November 2004

Tip: Looking for answers? Try searching our database.

Problem with Async WS

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ken - 12 Nov 2004 15:56 GMT
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
Derek Harmon - 14 Nov 2004 04:25 GMT
> 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
Ken - 15 Nov 2004 20:00 GMT
thanks..

> > I have an async Web service working inside a Try block just like MS says
> : :
[quoted text clipped - 39 lines]
>
> Derek Harmon

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.