JQuery AJAX调用WEB SERVICE方法

类定义

    /// 
    /// 员工信息
    /// 
    public class EmployeeEntity{
        /// 
        /// 员工姓名
        /// 
        public string EmployeeName{get;set;}

        /// 
        /// 生日
        /// 
        public string Birthday{get;set;}
    }

WEB SERVICE定义

    /// 
    /// JQuery测试服务
    /// 
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    [System.Web.Script.Services.ScriptService]
    public class Service1 : System.Web.Services.WebService{
        /// 
        /// 不含参数测试
        /// 
        /// 返回Hello World
        [WebMethod]
        public string HelloWorld(){
            return "Hello World";
        }

        /// 
        /// 带参数测试
        /// 
        /// 你的姓名
        /// 年龄
        /// 返回一段问候
        [WebMethod]
        public string GetHello(string yourName, int age){
            return string.Format("Hello {0} , your age is {1}", yourName, age);
        }

        /// 
        /// 获得类实例
        /// 
        /// 员工信息实体
        [WebMethod]
        public EmployeeEntity GetEmployeeEntity(){
            return new EmployeeEntity(){
                EmployeeName = "张三",
                Birthday = "2000-07-12"
            };
        }

        /// 
        /// 获得集合对象
        /// 
        /// 集合对象
        [WebMethod]
        public List GetList(){
            List countryList = new List();

            countryList.Add("中国");
            countryList.Add("美国");
            countryList.Add("法国");
            countryList.Add("德国");

            return countryList;
        }

        /// 
        /// 获得DataSet
        /// 
        /// DataSet对象
        [WebMethod]
        public DataSet GetDataSet(){
            DataSet     dataSet = new DataSet();
            DataTable   dataTable = new DataTable("employeeTable");

            dataTable.Columns.AddRange(new DataColumn[]{
                new DataColumn("EmployeeName",typeof(string)),
                new DataColumn("Age",typeof(int)),
                new DataColumn("Birthday",typeof(string))
            });

            dataTable.Rows.Add(new object[] { "李白", "63", "1320-05-06" });
            dataTable.Rows.Add(new object[] { "王刚", "60", "1920-05-06" });
            dataTable.Rows.Add(new object[] { "李毅", "53", "1820-05-06" });

            dataSet.Tables.Add(dataTable);
            return dataSet;
        }
    }

调用页面



    JQuery AJAX调用各种WEB SERVICE
    
    
    


    


你可能感兴趣的:(JS,.net,JS,JQ,AJAX,Webservice)