Troubleshooting WebException

Problem

We sometimes get a WebException which, as we try, we can't seem to catch. This results in an error popping up in the event log on the WebServer.

More details

We have an ASP.Net application that uses multiple web services. One of the webservice methods can take a long time. We use caching for this. When timed out, we use the ASP.Net Cacheing (CacheItemRemovedCallback) callback function to call the web service and refill the cache. Sample code below

Our problems start when the web service pauses from time to time. When this happens, it will throw a WebException. We put a Try / Catch block around our code and just catch and log exceptions. However, for some reason, this doesn't seem to catch the WebException, and I can't figure out why.

I have seen some strange behavior in the past where ThreadAbort exceptions were not thrown as expected. I wonder if this could be related? Also, another thing we do is create a new HTTPContext to access the cache. This works great and is necessary because the callback is not on the main request thread. I wonder if this could be related?

Any advice is appreciated!

Cheers James

Sample code

Generic Generic Sub CacheCallbackMethod ()

Try
    If HttpContext.Current Is Nothing Then
            HttpContext.Current = New HttpContext(New Hosting.SimpleWorkerRequest(String.Empty, String.Empty, New System.IO.StringWriter()))
        End If
    [Code to fetch data]
    Cache.Insert(key, obj, Nothing, Nothing, SlidingExpTimeSpan, Priority, CallbackMethod)
Catch ex As Exception

End Try

      

End function

0


a source to share


1 answer


This link explains it all:



http://msdn.microsoft.com/en-us/library/ms998562.aspx#scalenetchapt10_topic14

0


a source







All Articles