我确实读过这本书,因为缺乏对Netcore 2.1 the的支持
myItemsList = await App.MobileServiceAndroid.GetTable<MyTable>().ToListAsync();
当前在Android上不起作用,并且有一种变通方法是在MobileServiceClient的构造函数中传递HttpClientHandler(),所以我做到了:
public static MobileServiceClient MobileServiceAndroid =
new MobileServiceClient(AppConstants.AZURE_PRODUCTION_WEB_API_URL, new HttpClientHandler());
但这还不完整,仍然无法正常工作,我到底需要做什么才能使它起作用,因此非常感谢任何指导。
答案 0 :(得分:1)
据我了解,您正在使用Forms / PCL项目,而other solution正在其Android项目中实现此代码。
对您来说,将using Xamarin.Android.Net;
添加到班级后,您应该能够做到这一点:
public static MobileServiceClient MobileServiceAndroid =
new MobileServiceClient(AppConstants.AZURE_PRODUCTION_WEB_API_URL, new AndroidClientHandler());
很可能您在使用using语句时可能会遇到问题,因为您将必须遵循here所示的步骤,或者在以下步骤中为您定制:
ICustomClientHandler
using System;
using System.Net.Http;
namespace Test
{
public interface ICustomClientHandler
{
HttpClientHandler GetHandler();
}
}
CustomClientHandler
,它将是依赖项服务的Android部分,它将帮助您检索本机AndroidClientHandler using System.Net.Http;
using Xamarin.Android.Net;
using System.Runtime.CompilerServices;
using Xamarin.Forms;
using Test;
[assembly: Xamarin.Forms.Dependency(typeof(Test.Droid.CustomClientHandler))]
namespace Test.Droid
{
public class CustomClientHandler : ICustomClientHandler
{
public HttpClientHandler GetHandler()
{
return new AndroidClientHandler();
}
}
}
return new HttpClientHandler();
var clientHandler = DependencyService.Get<ICustomClientHandler>().GetHandler();
public static MobileServiceClient MobileServiceAndroid =
new MobileServiceClient(AppConstants.AZURE_PRODUCTION_WEB_API_URL, clientHandler);