asp.net 2.0 Ajax

Source: Internet
Author: User

ASP.net Ajax has raised the Web service to such an important position that it has almost become the most recommended implementation of ASP.NET AJAX server-side logic, because Web services are inherently designed purely for business logic. As we all know, the WEB service does not provide a "fancy" user interface, but rather focuses on the logical implementation of the program, which coincides with the idea of "completely separating the presentation layer from the business layer" advocated by the ASP.net AJAX client programming model- The client's ASP.net ajax framework is used to handle all the interface and user interaction functions of the program, and the server side only provides pure data and does not involve any presentation style.

By using the Web service client Access Proxy that is automatically generated by the ASP.net Ajax asynchronous communication layer, invoking the Web service to fetch data in the presentation layer code (that is, JavaScript) becomes an unusually simple thing- Its elegance even makes us believe that Ajax programs can be written so easily.

Next, we'll look at a simple example program to learn how to use JavaScript to asynchronously invoke a Web service in a asp.net ajax application. For demonstration purposes, the function of the program is very simple: the user enters the name in the text box of the page, and then clicks the button next to it, as shown in Figure 3-1.

Figure 3-1 user enters their own name in the interface

The program will use the ASP.NET Ajax asynchronous communication layer to send the user's name to the server-side web Service in AJAX mode. The Web service then generates a greeting message on the server side based on the user's name and sends it back to the client, and after the client receives the server response, it displays the greeting, as shown in Figure 3-2.

Figure 3-2 Program displays greetings from the server

Let's start with the server-side Web service. Create a new Web service class named Simplewebservice, where you declare a common Web service method--sayhello (). The method will accept a parameter named name and generate a greeting message to return:

[WebService(Namespace = "http://tempuri.org/")]
   [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
   public class SimpleWebService : System.Web.Services.WebService
   {
   [WebMethod]
   public string SayHello(string name)
   {
   return string.Format("Hello {0}!", name);
   }
   }

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.