ASMX接收类作为参数

时间:2016-07-14 17:13:50

标签: c# web-services asmx

我正在尝试为web方法接收类型类的参数。 我构建的类正在保存内部类的列表。 该课程看起来像这样

[Serializable]
public class InventoryCheckInput 
{

    public Item itemList { get; set; }

    [Serializable]
    public class Item
    {
        public string CatalogID { get; set; }
        public string Quantity { get; set; }
    }
}

网络方法看起来像这样

[WebMethod]
public InventoryCheckOutput OnlineInventoryCheck(InventoryCheckInput Items)
{
    return null;
}

可以像这样构建一个类参数吗?

1 个答案:

答案 0 :(得分:0)

您可以在客户端继承类和接收列表。

     public class requestResponse 
{
    public bool status { get; set; }
    public string msg  { get; set; }

}
 public class district : requestResponse
{
    public int district_id { get; set; }
    public string district_name { get; set; }

}
 [WebMethod]
    public List<district> getDropDown()
    {
        List<district> list = new List<district>();
        Pro_DbCon db = new Pro_DbCon();
        SqlConnection con = db.dbconnectionEMIS();
        try
        {
            con.Open();
            SqlCommand cmd = new SqlCommand("select * from DSS_District", con);
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                int idDistrict = Convert.ToInt32(dr[0]);
                string DistrictTitle = dr[1].ToString();

                district d = new district();
                d.status = true;
                d.msg = "";
                d.district_id = idDistrict;
                d.district_name = DistrictTitle;
                list.Add(d);
            }

            if (list.Count < 1)
            {
                district d = new district();
                d.status = true;
                d.district_id = 0;
                d.district_name = "No Data Found";
                d.msg = "";
                list.Add(d);
            }
            dr.Close();

        }
        catch (Exception ex)
        {
            con.Close();
            district s = new district();
            s.status = false;
            s.msg = ex.ToString();
            list.Add(s);

        }
        finally
        {
            con.Close();

        }


        return list;

    }