/// <summary>
/// 调用WebApi获取数据
/// </summary>
/// <typeparam name="TApi">WebApi接口类型</typeparam>
/// <typeparam name="TResult">返回数据</typeparam>
/// <returns>服务接口实例</returns>
public static ITask<ApiResultModel<TResult>> WebApi<TApi, TResult>(Func<TApi, ITask<ApiResultModel<TResult>>> func, string token = null)
where TApi : class, IHttpApiClient, IDisposable
{
var api = HttpApiClient.Create<TApi>();
AddHeaderToken(token, api);
return func(api);
}
/// <summary>
/// 调用WebApi获取数据
/// </summary>
/// <typeparam name="TApi">WebApi接口类型</typeparam>
/// <typeparam name="TResult">返回数据</typeparam>
/// <returns>服务接口实例</returns>
public static TResult WebApi<TApi, TResult>(Func<TApi, ITask<ApiResultModel<TResult>>> func, string token = null)
where TApi : class, IHttpApiClient, IDisposable
{
var api = HttpApiClient.Create<TApi>();
AddHeaderToken(token, api);
var resultModel = func(api).InvokeAsync().Result;
//if(resultModel.ReturnCode!=200)
// throw new NotImplementedException("还未实现");
// //抛出异常???
return resultModel.Result;
}
Created
March 14, 2018 09:05
-
-
Save wanghuaisheng/bf5d4f3a0a903cd581e8a2886ea5c9d9 to your computer and use it in GitHub Desktop.
WebApi调用删除的代码存档
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment