This time I will bring you a detailed explanation of the steps for jQuery ajax to call WCF services. What are theprecautions for jQuery ajax to call WCF services? The following is a practical case, let's take a look.
The example in this article describes how jQuery implements ajax to call WCF services. Share it with everyone for your reference, the details are as follows: Regarding AJAX calling WCF services, there are two methods: cross-domain and non-cross-domain. Today we will first introduce the non-cross-domain calling method. DEMO was written in VS2008. After testing and research, it was found that AJAX calling WCF service must meet the following conditions 1. The communication method of wcf must use webHttpBinding2. Must set < ;endpointBehaviors>The value of the node
3. The implementation of the service must add the mark
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json)]
Configuration fileCode
[ServiceContract] public interface IService1 { [OperationContract] string GetData(int value); [OperationContract] City GetDataUsingDataContract(City composite); [OperationContract] ListGetList(); [OperationContract] List GetListData(List list); } // 使用下面示例中说明的数据约定将复合类型添加到服务操作。 [DataContract] public class City { int seq = 0; string cityID; string ctiyName; [DataMember] public string CityID { get { return cityID; } set { cityID=value; } } [DataMember] public string CityName { get { return ctiyName; } set { ctiyName = value; } } [DataMember] public int Seq { get { return seq; } set { seq = value; } } }
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] public class Service1 : IService1 { [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)] public string GetData(int value) { return string.Format("You entered: {0}", value); } #region IService1 成员 [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json)] public City GetDataUsingDataContract(City composite) { City c = new City(); c.CityID = composite.CityID; c.CityName = composite.CityName; c.Seq = composite.Seq; return c; } [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json)] public ListGetList() { List list = new List (); City cc = new City(); cc.CityID = "1"; cc.CityName="北京"; cc.Seq = 3; list.Add(cc); City cc1 = new City(); cc1.CityID = "2"; cc1.CityName = "上海"; cc1.Seq = 4; list.Add(cc1); return list; } [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json)] public List GetListData(List list) { return list; } #endregion }
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WcfServiceDemoOne.WebForm1" %>
JQuery method of obtaining page width and height
##How to use JS jQuery to verify registration information Detailed explanation of the steps to obtain the radio value with jQueryThe above is the detailed content of Detailed explanation of the steps to call WCF service with jQuery+ajax. For more information, please follow other related articles on the PHP Chinese website!