views:

39

answers:

2

I am writing a control that will warn a user that their session is about to timeout. I can easily track standard postbacks and post packs in update panels, but I'm struggling to see how I can track calls made to any / all web services.

Is there a mechanism for this, or will I have to try and override the Sys.Net.WebRequest invoke code?

A: 

In a similar requirement, we wrote a HttpModule. At that point you could have a good control over your request and track your postbacks of webservices. See here for more information about how to write your own httpmodule http://msdn.microsoft.com/en-us/library/aa719858(VS.71).aspx

Subhash Dike
+1  A: 

There's nothing wrong in replacing the Sys.Net.WebRequest code - just keep a reference to the previous implementation and call it, after tracking the call. Something like this should do the trick:

(function() {
    var originalWebRequest = Sys.Net.WebRequest;
    Sys.Net.WebRequest = function() {
        // track call
        //...

        // call original WebRequest
        return originalWebRequest.apply(this, arguments);
    }
})();
Alexander Gyoshev
I tried this approach and what I'm finding is the functions (e.g. get_headers) are no longer part of the object. Is this because apply also need to apply something additional?
ilivewithian