asp.net c# 开发对外的WebService服务,获取数据

求大神给与解决 WebService服务
需要提供的查询条件,有四个:
d1:开始日期
d2:截止日期
id:ID
batchNo:学号
barcode:班级号
从数据表中(数据库可以是一个简单的数据库 -- 根据您的解答我在自己解决...主要是需要webservice服务给与解答)查得数据的结果。
数据的结果只返回某学科成绩数据。
取得数据规则:
1、如果存在班级号,将忽略其它条件,按班级号查询;
2、如果存在学号且班级号为空,将按学号查找,其它忽略;
3、没有以上两个条件,将按日期范围及ID查找。

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;

namespace test
{
    /// <summary>
    /// WebService 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]

    public class WebService : System.Web.Services.WebService
    {
        //模拟数据库
        private static List<User> users = new List<User>();
        static WebService()
        {
            //初始化模拟数据
            users.Add(new User() { data = DateTime.Now, id = 1, batchNo = "u1001", barcode = "c12", score = 95 });
            users.Add(new User() { data = DateTime.Now.AddDays(-1), id = 1, batchNo = "u1002", barcode = "c12", score = 96 });
            users.Add(new User() { data = DateTime.Now.AddDays(1), id = 1, batchNo = "u1003", barcode = "c12", score = 97 });
            users.Add(new User() { data = DateTime.Now, id = 1, batchNo = "u1004", barcode = "c12", score = 98 });
            users.Add(new User() { data = DateTime.Now, id = 1, batchNo = "u1005", barcode = "c13", score = 99 });
            users.Add(new User() { data = DateTime.Now, id = 1, batchNo = "u1006", barcode = "c13", score = 100 });
        }

        [WebMethod]
        public List<User> Query(DateTime d1, DateTime d2, int id, string batchNo, string barcode)
        {
            List<User> result = null;
            if (!string.IsNullOrEmpty(barcode))
            {
                result = users.FindAll(f => f.barcode.Equals(barcode));
            }
            else
            {
                if (!string.IsNullOrEmpty(batchNo))
                {
                    result = users.FindAll(f => f.batchNo.Equals(batchNo));
                }
                else
                {
                    result = users.FindAll(f => f.id == id && f.data > d1 && f.data < d2);
                }
            }
            return result;
        }
    }

    public class User
    {
        public DateTime data { get; set; }
        public int id { get; set; }
        public string batchNo { get; set; }
        public string barcode { get; set; }
        public int score { get; set; }
    }
}

温馨提示:答案为网友推荐,仅供参考
相似回答