Rest architecture in WCF two (WCF services that support Ajax)

Source: Internet
Author: User

I was in yesterday's article. The rest architecture in WCF, a rest overview, discusses the basic essentials of rest, and presents the concept of restfulness (rest) from Hi rest to LO rest (low rest). In today's article, I'll describe in detail the rest-style WCF services that you might be most familiar with: AJAX-enabled services. Such services should fall within the scope of Lo rest. Many people now intuitively equate "good" with "tall", thus underestimating the value of this lo-rest implementation. This article will tell you that this is not true and that the AJAX-enabled WCF service is strong enough.

Background information for the solution

I have a basic complete initial solution for the underlying work, and most of the code is part of the 12-set AJAX client library webcast series. This initial solution is designed to allow me to better demonstrate the power of AJAX-enabled WCF services, to avoid the lengthy steps required to create a service on the ground and then integrate with Ajax customers (how do you think the paradigm I've created is not very good, please try Supersefer, This is a Hebrew online store based on this paradigm. In this initial solution, pay special attention to two ASP.net AJAX controls: Catalog.js and Shoppingcart.js. The screenshot below is the display of the two controls

The catalog control is an important operational object in this article, and its task is to accept a specific data structure, display a page of product information for binding purposes, and when the user selects a product or clicks on the control to start the message, As for how the control interacts with the host home page (catalog.aspx), you can find it in the webcast series mentioned earlier. For the purposes of this article, we just need to focus on the following snippet in Catalog.aspx (host home), which has a GetData () method. When we implement the WCF service, we call it in this method. We will pass parameters such as startindex (starting index) and pagesize (the size of the page) to the WCF service (the return data for the service will be product information for the specified number of pages), and several callback methods (callback after the service call succeeds or fails). The callback method that invokes the success is also given below. This method directly obtains a reference to the catalog control ($get used to point to a control in ASP.net ajax). It then sets the index value of the current page and then sets the ProductInfo property with the data of the incoming callback function, which is our WCF payload. Finally, the function calls the control's DataBind method, which makes some DOM injections directly based on the data stored in the ProductInfo property.

Add a service

Adding a WCF service that supports Ajax is fairly straightforward. The first step is to add the service using the ' ajax-enabled WCF Service ' template. The process is as follows: Select "Add New Item" > select ' ajax-enabled WCF Service ' in Solution Explorer > name it CatalogService.cs > click ' Add '.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.