【问题标题】:How to use asp.net mvc web api when using the rest service使用rest服务时如何使用asp.net mvc web api
【发布时间】:2016-08-05 09:07:06
【问题描述】:

我有一个 webapi2.0 ,通过 webapi 我正在访问另一个用 java 实现的 restful 服务。

实际上我在这里只有一个问题,如何通过 webapi 实现多线程,因为当我点击服务时,我的一些静态类和其他相关数据不会填充。

任何人都可以帮助我了解其他服务。

这是我的代码:

public HttpResponseMessage ListEmployee() 
{ 
    Employee emp = new Employee{}; 
    List<Employee> EmployeeList = new List<Employee>{};
    var emp = emp.getlist(); 
    foreach(var item in emp)
    { 
        var details = emp.getDetails(item.id); 
    } 
    return WebApiResponse.Success<List<APICreatePatientModel>>(EmployeeList); 
} 

【问题讨论】:

  • public HttpResponseMessage ListEmployee() { Employee emp = new Employee{}; List EmployeeList = new List{}; var emp = emp.getlist(); foreach(var item in emp){ var details = emp.getDetails(item.id); } 返回 WebApiResponse.Success>(EmployeeList); }
  • 嘿@Martin Brandl,我已经分享了我的代码模式,我想同时打多个员工。

标签: asp.net asp.net-web-api


【解决方案1】:

也许对你有帮助,

$(document).ready(function () {
    // Send an AJAX request
    $.getJSON(apiUrl)
        .done(function (data) {
            // On success, 'data' contains a list of Employee.
            $.each(data, function (key, item) {
                // TODO as per you!.                    
            });
        });
});

更详细的可以去链接

http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api http://www.codeproject.com/Articles/344078/ASP-NET-WebAPI-Getting-Started-with-MVC-and-WebAP https://docs.asp.net/en/latest/tutorials/first-web-api.html

【讨论】:

  • 对不起,这不是问题的答案,因为我正在使用 webapi,我可以通过线程同时点击多个员工详细信息,但我检查过它也不起作用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多