标签:c android xamarin-ios xamarin-forms azure-mobile-services
我正在使用带有Xamarin Form Android应用程序的Azure Mobile Service来主要查询来自azure表存储的数据.
我面临的当前问题是azure移动服务客户端没有在移动服务客户端之后立即返回控制
API调用(仅适用于Portable类库和android app项目,但同一调用会返回正常.net中的结果
库,因为我已经使用测试项目来验证API).
我使用的源代码如下:
Azure移动服务代码:
public class VerticalFarmController : TableController<VerticalFarm>
{
protected override void Initialize(HttpControllerContext controllerContext)
{
base.Initialize(controllerContext);
MobileServiceContext context = new MobileServiceContext();
string connectionString = "My_StorageConnectionString";
DomainManager = new StorageDomainManager<VerticalFarm>(connectionString, "VerticalFarm", Request, Services);
}
public Task<IEnumerable<VerticalFarm>> GetAllVerticalFarm(ODataQueryOptions queryOptions)
{
return base.QueryAsync(queryOptions);
}
}
Xamarin Form Android应用程序代码:
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity
{
private const string ApiUrl = "[Mobile service Url]";
private const string AppKey = "[Application key]";
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
IMobileServiceClient mobileServiceClient = new MobileServiceClient(ApiUrl, AppKey);
try
{
var table = mobileServiceClient.GetTable("verticalfarm");
var result = table.ReadAsync("$top=10", null, wrapResult: true).Result;
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.ToString());
}
LoadApplication(new App());
}
}
在执行以下代码行之后,它既不返回结果也不返回异常:
var result = table.ReadAsync("$top=10", null, wrapResult: true).Result;
如果有人有类似的问题并且能够解决它,那将是很好的.
解决方法:
调用.Result如下所示会导致死锁
var result = table.ReadAsync("$top=10", null, wrapResult: true).Result;
我在MobileServicesClient.InvokeApiAsync()调用时遇到了同样的问题
相反,你应该等待: –
async Task ReadTable()
{
var result = await table.ReadAsync("$top=10", null, wrapResult: true);
// do something with result
}
或者在我的情况下
async Task CallApi()
{
var response = await App.client.InvokeApiAsync ("/api/call", System.Net.Http.HttpMethod.Get, null);
// do something with response
}
标签:c,android,xamarin-ios,xamarin-forms,azure-mobile-services 来源: https://codeday.me/bug/20190706/1399279.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。