2016-07-14 107 views
0

我試圖接收一個Web類型的類的參數。 我創建的這個類擁有一個內部類的列表。 類看起來像這樣ASMX接收類作爲參數

[Serializable] 
public class InventoryCheckInput 
{ 

    public Item itemList { get; set; } 

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

Web方法看起來像這樣

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

是有可能建立一個參數,像這門課嗎?

+3

你試過了嗎?這通常是最快的方法,看看是否可以完成。 – Tim

+0

你爲什麼要使用傳統技術?無論如何,這裏是XML Web Services支持的類型列表。 https://msdn.microsoft.com/zh-cn/library/3003scdt(v=vs.100).aspx –

+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; 

    }