我的Wep API方法:
[HttpGet]
public object getData()
{
var firstObj = dbContext.Customer();
var secondObj= dbContext.Department();
var thirdObj= dbContext.Email();
return new { firstObj,secondObj,thirdObj };
}
/* this is my client side call */
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", CommonHelper.CurrentToken);
client.BaseAddress = new Uri(CommonHelper.baseAddress);
HttpResponseMessage response = await client.GetAsync("/OPUS/Accounts/getData");
response.EnsureSuccessStatusCode();
}我从不同的表返回了多个对象。我需要从WEP API中的单个方法中获取这些值
发布于 2016-04-19 15:36:36
尝试执行以下操作,返回一个包含足够多值的匿名对象:
[HttpGet]
public HttpResponseMessage getData()
{
var firstObj = dbContext.Customer();
var secondObj= dbContext.Department();
var thirdObj= dbContext.Email();
return new { firstObj,secondObj,thirdObj };
}
/* this is my client side call */
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", CommonHelper.CurrentToken);
client.BaseAddress = new Uri(CommonHelper.baseAddress);
HttpResponseMessage response = await client.GetAsync("/OPUS/Accounts/getData");
response.EnsureSuccessStatusCode();
}发布于 2016-05-17 17:29:34
我可以通过一个WEB API方法获得所有的对象。
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", CommonHelper.CurrentToken);
client.BaseAddress = new Uri(CommonHelper.baseAddress);
HttpResponseMessage response = await client.GetAsync("/OPUS/Accounts/getData");
response.EnsureSuccessStatusCode();
var Lookups = await response.Content.ReadAsAsync<object>();
JObject _jObject = JObject.Parse(Lookups.ToString());
JArray deptStatus = _jObject["firstObj"] as JArray;
DeptTypeLookups = deptStatus .ToObject<ObservableCollection<Department>>();
JArray custStatus = _jObject["secondObj"] as JArray;
custTypeLookups = custStatus .ToObject<ObservableCollection<CustDetail>>();
}谢谢
https://stackoverflow.com/questions/36710942
复制相似问题