2016-08-02 75 views
1

多個輸入使用C#如何獲得在web服務

目前我使用的Web服務,以顯示員工詳細

當前邏輯

Getting the 4 inputs (employee id, name, date of join, email) as a string, sending the input to DB as a parameter and retrieve the procedure output in dataset and displayed the dataset output (employee id, name, date of join, email, address, passport no, etc). This is working fine for single employee information. 

現在我想大部分員工輸入並顯示批量員工輸出的網絡服務

如何獲取批量員工輸入詳細信息

例如,如果應用程序想獲得20條員工詳細信息,然後應用需要提供員工ID,姓名,加入的日期,電子郵箱爲20名員工輸入。

如何應用程序發送到通過數據集或任何其他想法爲20×4 = 80輸入的web服務的請求?

任意一個幫助或建議我

如果問題不明確或有任何疑問,請隨時問我。

+0

你開發的Web服務? –

+0

你使用什麼樣的網絡服務? –

+0

Web服務已經建立,我需要改變的邏輯,目前我得到4輸入一個字符串,按照新的要求,我需要拿到4輸入20次。如何獲得此 – Gopal

回答

1

通常對於這樣的事情,你需要做一個POST一些類型的數據連接BLOB(數據本身可以是你喜歡的任何格式,只要你的服務器會理解並作出相應的反應)的。你可以想象將所有這些都傳遞給URL,但那會有點瘋狂。

+0

完全同意。獲取請求具有最大長度限制 – Vladimir

1

您應該創建一個請求屬性像類:

public class RequestParams 
{ 
    public int employeeID { get; set; } 
    public string Name { get; set; } 
    public DateTime DateOfJoin { get; set; } 
    public string Email { get; set; } 
} 

這將是你的方法輸入PARAMS:

public EmployeesDetails GetDetails(RequestParams[] r) 

確保使用相同的結構在JavaScript和使用JSON.Parse來正確解析它

*編輯,例如:

[WebMethod] 
    public EmployeesDetails GetDetails(RequestParams[] request) 
    { 


     // Query the database, request contains an array of RequestParams 
    } 

public class RequestParams 
{ 
    public int employeeID { get; set; } 
    public string Name { get; set; } 
    public DateTime DateOfJoin { get; set; } 
    public string Email { get; set; } 
} 
public class EmployeesDetails 
{ 
    public int PassportNumber { get; set; } 
} 

JSON例子(不要抓我的分析錯誤,我寫的快速手動):

{'request':[ 
'RequestParams':{ 
    'employeeID':'1', 
    'Name':'1', 
    'DateOfJoin':'1', 
    'Email':'[email protected]'}, 
    { 
    'employeeID':'2', 
    'Name':'2', 
    'DateOfJoin':'2', 
    'Email':'[email protected]'}, 
    { 
    'employeeID':'3', 
    'Name':'3', 
    'DateOfJoin':'3', 
    'Email':'[email protected]'}, 
    { 
    'employeeID':'4', 
    'Name':'4', 
    'DateOfJoin':'4', 
    'Email':'[email protected]'} 
}]} 
+0

用戶需要發送批量輸入。按照新的邏輯用戶不想送4請求20倍,用戶需要發送4 * 20輸入作爲批量請求在一個時間 – Gopal

+0

這是exacly我的代碼是做.. 看看將WebMethod,因爲它接受對象 – Tomerz

+0

Tomerz數組,能否請您分享輸入和輸出一些示例代碼,我沒有完全理解你的邏輯:( – Gopal