jquery invokes a WCF service to pass a JSON object

Source: Internet
Author: User
Tags json web services client

The following example uses WCF to create a service port that can be accessed by the ASP.net page through a jquery Ajax approach, and we will use AJAX technology on the client to communicate with the WCF service. Here we only use jquery to connect to the Web service instead of using the ASP.net Ajax Library, as for why we don't use AJAX libraries, because we've already used jquery in our projects, and it's already able to handle all the Ajax requests and all the functionality, and If we were to use the ASP.net Ajax library, we would also have to include more than 80Kb of data (more in debug mode), but that's not to say that ASP.net Ajax libraries are not practical, in fact, if you use the same class library, we can write a lot of extra code less, But this example is to illustrate how we invoke Web services without a good client agent.

WCF Services:

We first create a website and then add a ajax-enabled WCF service to create a WCF services. (Make sure you're using the correct. Net Framework version, I'm using 3.5)

After we have added the service, it automatically enters the post code file for the service, and goes ahead and browse around the file for a second.

The first thing we have to do is to find "aspnetcompatibilityrequirements" and set its value to "allowed":

[Aspnetcompatibilityrequirements (Requirementsmode = aspnetcompatibilityrequirementsmode.allowed)]

This property is set to run our service in the ASP.net compatibility mode, and if we do not set the value to "allowed", then we cannot access the service through ASP.net, which is when you add "ajax-enabled WCF Service "is generated automatically. Please refer to MSDN for more details.

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.