ホームページ  >  記事  >  ウェブフロントエンド  >  jquery が wcf を呼び出して data_jquery を表示する方法

jquery が wcf を呼び出して data_jquery を表示する方法

WBOY
WBOYオリジナル
2016-05-16 18:05:031607ブラウズ

Chuangneng wcf が最初の選択肢です。コードは次のように非常に単純です:

コードをコピーします コードは次のとおりです:

System.Data を使用;
System.ServiceModel.Activation を使用;
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)]、
// を追加し、オペレーションに以下を含めますbody 行:
// WebOperationContext.Current.OutcomingResponse.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 には GetDataTable メソッドがあり、返されたデータの行数を示すパラメーター pz があり、返されたテーブルは jquery の json データとして使用されます。
ページ呼び出しメソッドも非常に単純です。 🎜 >



コードをコピー