Jquery calls wcf and shows the data method _ jquery

Source: Internet
Author: User
Tags connectionstrings
I have read a lot of examples of jquery calling wcf on the Internet, which may be the reason for the host. I used the gd host, so I didn't succeed. I made a day yesterday and finally succeeded, now I want to share the methods and code with you the preferred solution for creating wcf. The code is very simple, as shown below:

The Code is as follows:


Using System;
Using System. Data;
Using System. ServiceModel;
Using System. ServiceModel. Activation;
Using System. ServiceModel. Web;
Using System. Web. Script. Services;

[ServiceContract (Namespace = "")]
[AspNetCompatibilityRequirements (RequirementsMode = AspNetCompatibilityRequirementsMode. Allowed)]
[ServiceBehavior (IncludeExceptionDetailInFaults = true)]
Public class imgService
{
// To use http get, add the [WebGet] feature. (The default ResponseFormat is WebMessageFormat. Json)
// Create an operation to return XML,
// Add [WebGet (ResponseFormat = WebMessageFormat. Xml)],
// The operation body contains the following lines:
// WebOperationContext. Current. OutgoingResponse. ContentType = "text/xml ";
[OperationContract]
[WebGet (RequestFormat = WebMessageFormat. Json, ResponseFormat = WebMessageFormat. Json)]
// [WebInvoke (Method = "GET", RequestFormat = WebMessageFormat. Json, ResponseFormat = WebMessageFormat. Json, BodyStyle = WebMessageBodyStyle. WrappedRequest)]
Public DataTable GetDataTable (string pz)
{
// Add operation implementation here
DataSet ds = WebBase. GetDS (WebBase. meinvRepository, string. Empty, "body_id desc", pz );
If (ds. Tables. Count> 0)
Return ds. Tables [0];
Return null;
}

// Add more operations here and mark them with [OperationContract]
}



For details, the getable able method of wcf has a parameter pz indicating the number of rows of returned data. The returned table is given to jquery as json data.

The page call method is also simple:

The Code is as follows:


<% @ Page Language = "C #" EnableViewState = "false" AutoEventWireup = "true" CodeFile = "Default. aspx. cs"
Inherits = "jquerywcf_Default" %>




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.