Using AJAX Extensions clients for Web service calls

Source: Internet
Author: User
Tags web services visual studio

Fundamentally, ASP.net is a server-side technology from beginning to end. Of course, in some cases asp.net generates client JavaScript, especially in validation controls and in the new Web part infrastructure, but it typically simply converts client properties to client behavior. As a developer, you do not have to consider interacting with the client until you receive the next POST request. For developers who need to use client JavaScript and DHTML to build more interactive pages, they need to write their own code with some help from the ASP.net 2.0 script callback feature. The situation was radically changed last year.

Microsoft published a new ASP.net plug-in (code-named "Atlas") at Microsoft's Professional Developers conference in September 2005, primarily to take advantage of client JavaScript, DHTML, and Xmlhttpreques T object. The goal is to help developers create more interactive, AJAX-enabled WEB applications. This framework has since been renamed to the official name Microsoft®ajax Library and asp.net 2.0 AJAX Extensions, which provides many outstanding features, including client data binding, DHTML animation and behavior, and the use of UpdatePanel implementation Good to intercept the client POST callback. Many of these features rely on the ability to asynchronously retrieve data from the server in the form of parsing and interacting easily through client JavaScript calls. The theme of this month's column is this new and useful ability to invoke server-side WEB services through client JavaScript in pages that support ASP.net 2.0 AJAX Extensions.

Invoking Web services using AJAX

If you have ever used a WEB service in the Microsoft. NET Framework, whether you use the Wsel.exe utility to create a proxy or use the Visual studio® Add Web Reference feature, you are accustomed to using the. NET type to invoke the WEB Services. In fact, invoking a Web service method through a. NET proxy is very similar to calling a method on another class. The agent prepares the XML based on the parameters you pass, and it properly converts the XML response it receives to the. NET type specified by the proxy method. Developers can easily leverage the. NET Framework to use Web service endpoints, which also makes current service-oriented applications feasible.

asp.net 2.0 AJAX Extensions enables client JavaScript, which runs in the browser, to achieve seamless, identical proxy generation experience with WEB services. You can write an. asmx file that is hosted on your server and invoke the method on the service through a client JavaScript class. For example, Figure 1 shows a simple. asmx service, which implements a simulated stock quote retrieval (using random data).

Figure 1 Stockquoteservice.asmx

<%@ WebService language= "C #"
class= "Msdnmagazine.stockquoteservice"%>
using System;
Using System.Web;
Using System.Web.Services;
Using System.Web.Services.Protocols;
From Microsoft.Web.Extensions.dll assembly
using Microsoft.Web.Script.Services;
Namespace Msdnmagazine
{
[WebService (Namespace = "Http://msdnmagazine.com/ws")]
[WebServiceBinding ( ConformsTo = wsiprofiles.basicprofile1_1)]
[ScriptService] public
class Stockquoteservice:webservice
   {
static Random _rand = new Random (environment.tickcount);
[WebMethod]
public int getstockquote (string symbol)
{return
_rand.    Next (0,);
}
}

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.