>  기사  >  웹 프론트엔드  >  jquery가 wcf를 호출하고 data_jquery를 표시하는 방법

jquery가 wcf를 호출하고 data_jquery를 표시하는 방법

WBOY
WBOY원래의
2016-05-16 18:05:031607검색

Chuangneng wcf가 첫 번째 선택이며 코드는 다음과 같이 매우 간단합니다.

코드 복사 코드는 다음과 같습니다.

System.Data 사용,
System.ServiceModel.Activation 사용,
System.ServiceModel.Web 사용; System.Web.Script.Services 사용;

[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
public class imgService
{
// HTTP GET을 사용하려면 [WebGet] 속성을 추가하세요. (기본 ResponseFormat은 WebMessageFormat.Json)
// XML을 반환하는 작업을 만들려면
// [WebGet(ResponseFormat=WebMessageFormat.Xml)],
//을 추가하고 작업에 다음을 포함합니다. 본문 줄:
// 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)
{
// 여기 작업 구현 추가
DataSet ds = WebBase.GetDS(WebBase.meinvRepository, string.Empty, " body_id desc",pz)
if (ds.Tables.Count > 0)
return ds. [0];
return null;
}

// 여기에 작업을 더 추가하고 [OperationContract]
}



설명 wcf에는 반환된 데이터의 행 수를 나타내는 매개변수 pz가 있습니다. 반환된 테이블은 jquery의 json 데이터로 사용됩니다.

페이지 호출 방법도 매우 간단합니다.




코드 복사 코드는 다음과 같습니다. <%@ Page Language="C#" EnableViewState="false " AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="jquerywcf_Default" %>









>