I am using Azure Mobile Service with the Xamarin Form application for Android to basically request data from the azure storage.
The current problem that I encountered is that the azure mobile service client does not return control immediately after the mobile service client API call (this only happened with the portable class library and the Android application project, but the same call returns the result in regular .net since I used a test project to test the API).
The source code I used is as follows:
Azure Mobile Service code:
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 Application Code:
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()); } }
It does not return a result or exception immediately after the execution of the following line of code:
var result = table.ReadAsync("$top=10", null, wrapResult: true).Result;
It would be great to know if anyone has a similar problem and were able to solve it.
source share