Chapter 4. Consuming RESTful Services

In this chapter, we will discuss how we can consume RESTful Services using various clients to perform CRUD operations.

In this chapter, we will cover the following points:

  • Understanding Ajax
  • Introducing JSON and jQuery
  • An overview of Language Integrated Query (LINQ)
  • Consuming Security Service
    • Using an ASP.NET client
    • Using an ASP.NET MVC client
    • Using a WPF client

Before we discuss how we can consume WCF RESTful Services, let's take a quick look at LINQ, because we will be using it for querying data throughout this book.

Understanding AJAX

Asynchronous JavaScript and XML (AJAX) is a technology that is used to build applications with fast and responsive user interfaces. AJAX can be used to reduce web page postbacks significantly, thus yielding better response time. Not only can you use AJAX to reduce page hits, but also to submit portions of your web page to the web server in order to reduce network traffic.

Note

Note that Unobtrusive AJAX is the latest evolution of AJAX. This version of AJAX presents a clean separation of behavior (JavaScript), content (HTML), and presentation (CSS), and can work even when JavaScript is turned off in your browser. Unobtrusive AJAX helps make your web applications work irrespective of whether JavaScript is turned off in your web browser. It works even on a mobile phone, screen reader, or the Web.

The technologies that make up AJAX are as follows:

  • XMLHttpRequest: The XMLHttpRequest object is used for the exchange of data between a server and client. Almost all modern-day browsers have an inbuilt XMLHttpRequest object.
  • JavaScript: This is an interpreted, prototype-based scripting language with support for dynamic typing, which enables the client scripts to interact with the controls in a web browser.
  • DHTML: This is a collection of technologies that can be used to create interactive, intuitive, and dynamic user interfaces. It is also known as Dynamic HTML.
  • DOM: Document Object Model (DOM) is a cross-platform, language-independent standard API, which is used to represent objects in HTML, XHTML, and XML documents.
  • XML: Extensible Markup Language (XML) is a flexible text-based markup language, which provides a standard that defines the rules for encoding documents.

The advantages of using AJAX are:

  • Improved responsiveness
  • AJAX helps us in sending small payloads
  • Asynchronous processing and reduced network traffic
  • Platform and architecture neutrality

Cross-Origin Resource Sharing (CORS) is a concept that enables AJAX requests to be posted to a domain that is different from the domain of the client. The modern-day browsers, such as Internet Explorer 8+, Firefox 3.5+, Safari 4+, and Chrome provide support for CORS. You can get to know more about CORS at http://www.bennadel.com/blog/2327-Cross-Origin-Resource-Sharing-CORS-AJAX-Requests-Between-jQuery-And-Node-js.htm.

AJAX is heavily dependent on JavaScript, due to which providing multibrowser support applications that use AJAX is a challenge. Also, usage of AJAX makes your web pages difficult to debug and prone to security threats due to the massive usage of JavaScript.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset