简体   繁体   English

无法执行从Android到Azure移动服务的插入操作

[英]Unable to perform Insert Operation from Android to Azure Mobile Service

I am trying to perform insert operation from Android to Azure Mobile service without success. 我试图执行从Android到Azure移动服务的插入操作,但未成功。 I am able to perform insert from the Web Try it out, but not from Android. 我可以从网上执行插入,但不能从Android上进行。 I was able to perform the insert with the Todoitem object but not with my own. 我可以使用Todoitem对象执行插入操作,但是不能使用我自己的对象执行插入操作。

Here is the database 这是数据库 在此处输入图片说明

And here is my Java Class 这是我的Java类

public class Bill {
    public String Id;
    public String UserId;
    public String BillName;
    public double BillAmount;
    public Date BillDueDate;
    public Boolean Paid;
}

And here is my Mobile Services Usage 这是我的移动服务使用情况

MobileServiceTable<Bill> mBillTable = mClient.getTable("Bills", Bill.class);

    Bill mBill = new Bill();
    mBill.BillAmount = 33.50;
    mBill.UserId = "2";
    mBill.BillDueDate = new Date(System.currentTimeMillis());
    mBill.BillName = "Android Phone Bill";
    mBill.Paid = true;


   Log.i(TAG, "Calling Insert");
   mBillTable.insert(mBill, new TableOperationCallback<Bill>() {

        @Override
        public void onCompleted(Bill entity, Exception exception, ServiceFilterResponse response) {
            Log.i(TAG, "Called insert");
            if (exception == null){
                Log.i(TAG, "Azure insert succeeded ID: " + entity.Id);
            } else {
                Log.i(TAG, "Azure insert failed again " + exception);
            }
        }
    });
    return rootView;

No matter what I do, I get the following error 无论我做什么,都会出现以下错误

Azure insert failed again com.microsoft.windowsazure.mobileservices.MobileServiceException: Error while processing request. Azure插入再次失败com.microsoft.windowsazure.mobileservices.MobileServiceException:处理请求时出错。

What I am I doing wrong? 我做错了什么? For some reason the database is showing multiple connections but no data is being inserted. 由于某种原因,数据库显示了多个连接,但未插入任何数据。 I do have one active connection from Visual Studio to this database, I am not sure if that is denying more connection 我确实有一个从Visual Studio到此数据库的活动连接,我不确定这是否拒绝更多连接

I finally got this to work after many frustrating hours. 经过数小时的挫折后,我终于可以使用它了。 First it was the Starbucks wifi connection that was somehow blocking connectivity to Azure Mobile Service. 首先是星巴克wifi连接,以某种方式阻止了与Azure移动服务的连接。 I got around this by using my phone instead of an Emulator to test. 我通过使用手机而不是仿真器来解决此问题。 Then there is the challenge of figuring out what is the exact Table name that the ZUMO service expects. 接下来,要弄清楚ZUMO服务期望的确切表名是什么。

I am using the .Net backend and created my database using EF Code first migration like so 我正在使用.Net后端并使用EF Code首先迁移来创建数据库,如下所示

public DbSet(Bill) Bills { get; 公共DbSet(Bill)帐单{get; set; 组; } }

Given this context, when I publish to ZUMO a database table named Bills was created like so 在这种情况下,当我发布到ZUMO时,创建了一个名为Bills的数据库表,如下所示 表名称Azure移动服务

So I guessed (wrongly) that the table name I should be calling from my Android client is "Bills" , turned out that for some reason Azure Mobile sees the table name as "Bill" which was the model class that was used to create the Entity Framework context. 因此,我猜(错误地),我应该从Android客户端调用的表名是“ Bills”,结果是由于某种原因,Azure Mobile将该表名视为“ Bill”,这是用于创建该表名的模型类。实体框架上下文。 I realized this using the Web Try it out 我通过网络意识到了这一点

Azure移动服务试用

So proceed cautiously with the .Net backend for Azure Mobile service, it seems to have a few gotchas to watch out for. 因此,请谨慎使用Azure移动服务的.Net后端,它似乎需要注意一些陷阱。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM