Professional Documents
Culture Documents
It405 Week 06
It405 Week 06
It405 Week 06
Problem: To eliminate bad calls from forcing good calls to time out and
create time
Solution: modify the ASP.NET AJAX runtime and introduce automatic
retry.
Caching Web Service Responses on the
Browser
Browsers can cache images, JavaScript, and CSS files on a users hard drive.
They also cache XML HTTP calls if the call is an HTTP GET and not an HTTP
POST as the cache is based on the URL.
The browser will cache any HTTP GET call and return cached data based on
the URL.
Create an XML HTTP call as HTTP GET and the server returns a special
header.
The browser will cache the response which will be returned from the cache
on future calls.
This action saves the delay of a network roundtrip and download time
increasing client-side performance.
Using HTTP GET calls instead of HTTP
POST
ASP.NET AJAX, by default, uses HTTP POST for all web service calls which is
expensive. Instead use HTTP GET to reduce costs.
HTTP GET does not allow you to pass objects as parameters, only numerics,
strings, and dates.
When making an HTTP GET call, ASP.NET AJAX builds an encoded URL and hits
that URL up to 2,048 characters.
To enable HTTP GET on a web service method, decorate the method with the
ScriptMethod attribute.
Working with the this function
XML HTTP callbacks are not executed on the same context where
they are called.
If you are make a web method call from a JavaScript class you get
null on the debug console because this is no longer the instance of
the class, which is a common mistake.
When JavaScript events are raised that this refers to the HTML
element that produces the event.
Use ButtonID so the button is making the call. The call is made
within the button objects context so refers to the button object,
not the instance of the class.
Working with the this function (cont)
XML HTTP raises the event onreadystatechanged and
ASP.NET
AJAX traps and fires the callback.
The code execution is still on the XML HTTPs context.
Its the XML HTTP object that raises the event and refers
to the XML HTTP object, not your own class where the
callback is declared.