我是 xamarin 和 azure easy table 的新手。我只是想尝试一下。我遵循了几个例子,例如 cups of coffee和 Xamarin 大学的待办事项列表。我成功部署了我的简易表。但是,当我尝试编写自己的连接并插入时。好像不行。
下面是我的初始化代码:
var Client = new MobileServiceClient("http://appname.azurewebsites.net");
var path = Path.Combine(MobileServiceClient.DefaultDatabasePath, "escapedb.db");
var store = new MobileServiceSQLiteStore(path);
store.DefineTable<InventoryModel>();
await Client.SyncContext.InitializeAsync(store);
inventoryTable = Client.GetSyncTable<InventoryModel>();
下面是我的插入代码:
var test = new InventoryModel() { Id = "12344", Name = "Sample", Quantity = 1 };
await inventoryTable.InsertAsync(test);
await SyncInventory();
当调用insert时,会抛出错误 Microsoft.WindowsAzure.MobileServices.Sync.MobileServicePushStatus.CancelledByNetworkError
这是我的库存模型:
public class InventoryModel
{
[Newtonsoft.Json.JsonProperty("id")]
public string Id { get; set; }
[Newtonsoft.Json.JsonProperty("name")]
public string Name { get; set; }
[Newtonsoft.Json.JsonProperty("quantity")]
public int Quantity { get; set; }
}
如何解决这个异常?我有互联网连接。 我只想与我的 azure 服务进行通信。 感谢您的帮助。
最佳答案
When it calls insert, it throws an error Microsoft.WindowsAzure.MobileServices.Sync.MobileServicePushStatus.CancelledByNetworkError
MobileServicePushStatus.CancelledByNetworkError
表示您的推送操作由于网络错误而中止。我建议你捕获MobileServicePushFailedException处理同步操作时。更多详情,您可以引用Handling Conflict Resolution 。另外,您可以利用 Fiddler用于收集网络跟踪并检索详细的错误消息以缩小此问题的范围。另外,在处理同步操作时,我建议您引用Detecting Connection State .
此外,您可以尝试通过浏览器访问您的移动应用来隔离此问题,并确定该问题是否是由于您设备的网络造成的。如需浏览您的移动应用程序,您可以引用The HTTP Table Interface .
关于azure - Xamarin Azure Easy Table 连接 CancelledByNetworkError 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45332016/