RestService.cs
并试图调用
来自视图模型FirstViewModel.cs
IntIRestService.cs
RestService.cs
namespace SqliteDemo.core.Services
{
public class RestService : IntIRestService
{
public async Task<List<People>> GetSalesPeopleAsync()
{
try
{
//Declare a Http client
var client = new HttpClient();
//Add a Base URl
client.BaseAddress = new Uri(Constants.MUrl);
//Add the response type
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
//Add the API
var response = await client.GetAsync("iCodersLab/Custom-ListView-Using-Volley/master/richman.json");
var content = await response.Content.ReadAsStringAsync();
//return content;
}
catch (Exception ex)
{
var t = ex.Message;
}
return null;
}
}
}
FirstViewModel.cs
namespace SqliteDemo.core.ViewModels
{
public class FirstViewModel
: MvxViewModel
{
public event EventHandler mNetworkClick;
public ICommand networkTask
{
get;
set;
}
public FirstViewModel()
{
networkTask = new MvxCommand<string>(param =>
{
//Calling Service here
});
}
}
}
IntIRestService.cs
namespace SqliteDemo.core.Services.ServiceInterfeces
{
public interface IntIRestService
{
Task<List<People>> GetSalesPeopleAsync();
}
}
答案 0 :(得分:0)
IntIrestService是界面,您无法实例化界面 您需要实例化实现接口的具体类。
IntIrestService intIrestService = new RestService();