Ext call asp.net AJAX WebService

Source: Internet
Author: User
Tags config json serialization

In ASP.net Ajax, making the client call WebService very simple, and very useful (personally feel that this function is the core of ASP.net Ajax, a lot of interaction with the client needs a function to assist implementation). That in ext, the standard client interacts with the server, uses the custom HttpHandler, and the server handles the client to submit the parameter also must be the weak type use way, also may use with certain inconvenience. If you've ever used asp.net ajax to call WebService, you'd really like ext to be able to invoke webservice as simple as that.

By default, ext can also call WebService, in this blog has introduced the "ExtJS and. NET Development example (bulk deletion of grid)." But when you pass in multiple arguments and output JSON strings at call time, you need to use the ASP.net Ajax WebService method to invoke it.

WebService that can be invoked by ASP.net Ajax must be marked System.Web.Script.Services.ScriptServiceAttribute. Depending on what we need, we can also specify the serialization of its output for each WebService method. By default, JSON serialization is used, and of course we can use XML serialization.

By studying the WebServiceProxy class of ASP.net Ajax, and fiddler to observe the request webservice to the server. It is not hard to find that the only difference between ASP.net Ajax calls WebService ordinary requests is that the Content-type value it delivers in the request header is application/json;utf-8. And this is the key to ext call asp.net Ajax WebService, we only need to be in the request of the head of the Content-type pass this value on the line (note, must only be this value, if you add other strings can not be invoked).

The parameters passed to the WebService must also have certain rules. With Get and post requests, there are different ways to pass the argument, respectively. If you use a POST request, you need to serialize the user pass parameter as an object into a JSON string, and when it is a GET request, you can use the default reference method (the normal address bar passes to connect different parameters with &).

As long as you strictly follow these two request rules, you can access the ASP.net ajax WebService correctly.

Create a new Ext.data.EnhancedConnection class, inherit from Ext.data.Connection,

Ext.data.EnhancedConnection = function(config){
    Ext.apply(this,config);
    Ext.data.EnhancedConnection.superclass.constructor.call(this);
}

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.