2016-08-02 72 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