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" %>