Content proxy is a web service on your server that can fetch data from external URLs and return it to the browser (see Figure ).
The browser makes a call to the proxy to fetch data from an external URL
The proxy can cache the response on the server for some period and thus save repeated calls to same external URL.For example, if a hundred users subscribe to the same RSS feed and the feed does not change for days, the proxy can cache the response from the feed source for one day and serve hundreds and thousands of users directly from its server-side cache (see Figure).
Server-side caching greatly improves load time for users because there ’s only one network roundtrip.The server doesn’t have to go to the external source.The proxy can also produce response headers that will tell the browser to cache the response on the browser for a period of time. During this time,the same call to the proxy will be served from the browser cache and complete blazingly fast.There’ll be no net work round trip at all on sub sequent calls to same data from the proxy (see Figure ).
The proxy caches data on the server and prevents repeatedly calling the same external source for multiple users
When a response is cached on the browser, it does not make call to the proxy and thus there’s no network roundtrip at all,
This means if we use a proxy to fetch RSS feeds and cache the response in the browser for an hour,and the user goes to another web site and comes back, the RSS wid gets will load instantly with out making a call to the server. So,if you have only RSS widgets on your page, the whole page will load in just one call to Default.aspx. Every thing else is already cached on the browser.Chapter 9 explains how client-side caching can be used to speed up RSS loading.
Content Proxy Web Service
Proxy.asmx is the content proxy web service. It has three methods:
GetString( url, cacheDuration )
Returns data from the URL in string format and caches on the browser for a specified duration
Returns XML from a specified URL and caches the response on the browser for a specified duration
GetRss( url, count, cacheDuration)
Returns the RSS feed converted to a LINQ projection (discussed in Chapter 3) from a specified URL and caches the feed on the server for 15 minutes and on the client for a specified cache duration
GetString and GetXml are simple; they just use WebClient to get data from the original URL and cache the response (see Example ).
However, GetRss is a bit more complicated.It downloads the feed and caches it using ASP.NET cache for 15 minutes.So, subsequent calls to the same feed are returned from the ASP.NET cache.GetRss also generates a proper response cache header to cache the response on the browser for a specified duration.So, the widget consuming RSS via proxy can control how long to cache the response on the browser.
Example shows the same RSS loading and parsing code that was in the RSS widget in Chapter.
GetRss on a proxy web service
GetRss on a proxy web service(continued)
GetRss on a proxy web service(continued)
Challenges with the Proxy Web Service
The external services’ response time is unpredictable and unreliable.Sometimes a heavily loaded external service might take 20 to 30 seconds to complete which means the call to the proxy will get stuck for 20 to 30 seconds. If that happens to 100 incoming requests within a 20- second period, all of the available ASP.NET worker thread will be used. Your web application will no longer serve any requests until the proxy requests either complete or timeout and release the ASP.NET worker thread.
This will create a slowloading web site or a completely nonresponsive web site. Chapter discusses the scalability challenges web applications have that heavily depend on web services and fetch a majority of the content from external services.
ASP.NET Related Interview Questions
|VB.NET Interview Questions||C#. NET Interview Questions|
|ASP.NET Interview Questions||ADO.Net Interview Questions|
|Windows Presentation Foundation(WPF) Interview Questions||Windows CE .NET Interview Questions|
|Dot Net Framework Interview Questions||Asp Dot Net Mvc 4 Interview Questions|
|Asp Dot Net Mvc Interview Questions|
Introducing Web Portals And Dropthings.com
Architecting The Web Portal And Widgets
Building The Web Layer Using Asp.net Ajax
Building The Data And Business Layers Using .net 3.5
Building Client-side Widgets
Optimizing Asp.net Ajax
Creating Asynchronous, Transactional, Cache-friendly Web Services
Improving Server-side Performance And Scalability
Improving Client-side Performance
Solving Common Deployment, Hosting, And Production Challenges
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.