我建个android app和Windows Azure的Mobile Service配合,以实现会员注册的功能,实际十分简单,微软家的东西真心好用

首先新建个Mobile Service

New->Mobile Service->Create之后弹出下图的对话框

URL就自定义一个,如果有人注册了会报错,换个就好,database新建还是使用已存在的都可以,新建之后会多一步让你输入要新建的数据库的名称和密码,backend就选Javascript,点击箭头下一步

使用现存的会让你输入密码,建立完成,点击主界面左侧的Mobile service,出现下图

我这里选“连接一个已存在的android app”,其实现在下面微软的教程就放在那里了

在自己的android app中确保build.gradle(project:你自己的工程名)里面有:

repositories {
jcenter()
}

build.gradle(project:Model:app)中添加windows azure sdk,就是把这几句添加到dependencies里去:

   compile 'com.google.code.gson:gson:2.3'
compile 'com.google.guava:guava:18.0'
compile 'com.microsoft.azure:azure-mobile-services-android-sdk:2.0.3'
compile (group: 'com.microsoft.azure', name: 'azure-notifications-handler', version: '1.0.1', ext: 'jar')

在自己的实现MobileService功能代码中添加:

private MobileServiceClient mClient;
private ProgressBar mprogressBar;
  try {
mClient=new MobileServiceClient("你的URL",
"你的KEY",
this).withFilter(new ProgressFilter()); mStudentTable=mClient.getTable(Student.class);
} catch (MalformedURLException e) {
e.printStackTrace(); createAndShowDialog(new Exception("移动服务发生错误,检查URL和Key试试"), "Error");
}
private class ProgressFilter implements ServiceFilter {

        @Override
public ListenableFuture<ServiceFilterResponse> handleRequest(
ServiceFilterRequest request, NextServiceFilterCallback next) { runOnUiThread(new Runnable() { @Override
public void run() {
if (mprogressBar != null) mprogressBar.setVisibility(ProgressBar.VISIBLE);
}
}); SettableFuture<ServiceFilterResponse> result = SettableFuture.create();
try {
ServiceFilterResponse response = next.onNext(request).get();
result.set(response);
} catch (Exception exc) {
result.setException(exc);
} dismissProgressBar();
return result;
}
}
private void dismissProgressBar() {
runOnUiThread(new Runnable() { @Override
public void run() {
if (mprogressBar != null) mprogressBar.setVisibility(ProgressBar.GONE);
}
});
}

上面代码中的“你的URL”和“你的KEY”替换成你自己新建的Mobile Service的URL和KEY,其实在现在向导里面有的,没有单击上面的“DASHBOARD”,你的URL和key如图

关于KEY,点击MANAGE KEYS,等一秒,复制那个Application key。

接下来,定义那个要传送的实体类Student

import com.google.gson.annotations.SerializedName;

import java.util.Objects;

/**
* Created by chen on 2015/9/19.
*/
public class Student { @SerializedName("id")
private String mID; @SerializedName("stuid")
private String mStuID; @SerializedName("name")
private String mName; @SerializedName("sex")
private String mSex; @SerializedName("qq")
private String mQQ; //Constructor
public Student(){ } public Student(String id,String stuid,String name,String sex){
this.setID(id);
this.setStuID(stuid);
this.setName(name);
this.setSex(sex);
} public void setID(String id) {
this.mID = id;
} public void setName(String name) {
this.mName=name;
} public void setSex(String sex) {
this.mSex = sex;
} public void setStuID(String stuID) {
this.mStuID = stuID;
} public void setStuQQ(String stuQQ){this.mQQ=stuQQ;} @Override
public String toString(){return getName();} public String getName(){return mName;} public String getID(){return mID;} public String getStuID(){return mName;} public String getSex(){return mSex;}
}

注意:实体类中类似@SerializedName("id")里面的“id”要和接下在azure管理中定义的Column名字一致,官方文档中说,只要一致mobile service就会自己解析json并将其对应存储到数据库中。

下面就定义数据库,如图,在azure的管理界面上,如图点DATA,选自己的数据库,新建张表,表中的Column要和上面的实体类一致,最终的效果应该这样

运行安卓客户端,success!

Windows Azure之Mobile Service的更多相关文章

  1. [Windows Azure] How to use the Windows Azure Blob Storage Service in .NET

    How to use the Windows Azure Blob Storage Service in .NET version 1.7 version 2.0 This guide will de ...

  2. 跟我学Windows Azure 四 Cloud Service中的WebRole与WorkRole,及他们之间的通信

    Cloud Service 中WebRole就相当与我们的WebSite,而WorkRole相当与我们在服务器上写了个Windows Service,站在高可用的角度上来讲,Cloud Service ...

  3. [iOS]使用Windows Azure來做iOS的推播通知 (转帖)

    這一篇我們用Windows Azure 的Mobile Service 來實作iOS的推播通知,底下我們分成三個階段來探討如何實作推播通知的服務: 第一階段: 開啓你的Windows Aure服務   ...

  4. Windows Azure Service Bus Topics实现系统松散耦合

    前言 Windows Azure中的服务总线(Service Bus)提供了多种功能, 包括队列(Queue), 主题(Topic),中继(Relay),和通知中心(Notification Hub) ...

  5. Windows Azure Service Bus Notification Hub推送通知

    前言 随着Windows Azure 在中国的正式落地,相信越来越多的人会体验到Windows Azure带来的强大和便利.在上一篇文章中, 我们介绍了如何利用Windows Azure中的Servi ...

  6. Windows Azure Service Bus (1) 基础

    <Windows Azure Platform 系列文章目录> 我们在基于Windows Azure进行云端开发的时候,云端的软件通常都需要与其他软件进行交互.这些其他软件可能包括其他In ...

  7. windows azure Vm、cloud service、web application 如何选择可用的服务

    windows azure 的web应用和虚拟机都经常用.我们经常把我们的网站部署上去.一般选择web应用或者开一个虚拟机.开一个虚拟机就会按照虚拟机的使用时间进行计费. 那么我们选择web部署在哪里 ...

  8. [Windows Azure] How to use the Queue Storage Service

    How to use the Queue Storage Service version 1.7 version 2.0 This guide will show you how to perform ...

  9. [Windows Azure] How to use the Table Storage Service

    How to use the Table Storage Service version 1.7 version 2.0 This guide will show you how to perform ...

随机推荐

  1. Linux中vim编辑器莫名下方出现H的问题

    在使用vim编辑文件的时候,不知道自己是按了哪个快捷键,导致了,每次编辑文件时,下方命令行出现数字+H的格式命令,使得整个文件没法编辑,强制退出后进入不能解决问题,各种文件的编辑都不行,找不出原因,最 ...

  2. Quartz 入门详解 专题

    Cron-Expressions are used to configure instances of CronTrigger. Cron-Expressions are strings that a ...

  3. Canvas范围裁切和几何变换

    范围裁切 clipRect() canvas.save(); canvas.clipRect(left, top, right, bottom); canvas.drawBitmap(bitmap, ...

  4. 【77.39%】【codeforces 734A】Anton and Danik

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  5. MyCat负载均衡 下篇

    MyCat负载均衡 下篇   之前在 一步一步在Windows中使用MyCat负载均衡 上篇 中已经讲了如何配置出MyCat.下面讲其相关的使用. 五.配置MyCat-eye 对于MyCat监控官网还 ...

  6. explanatory variable(independent vs dependent)、design matrix

    design matrix(设计矩阵) 是统计学上的概念,一般标记为 X,是由一组对象的解释变量(explanatory variables)构成的矩阵. 1. explanatory variabl ...

  7. WPF实现抽屉效果

    原文:WPF实现抽屉效果 界面代码(xaml): <Window x:Class="TransAnimation.MainWindow" xmlns="http:/ ...

  8. Android 位置服务——BaiduLocation的使用

    原文:Android 位置服务--BaiduLocation的使用 版权声明:本文为博主原创文章,欢迎转载,转载请在文章显眼处说明文章出处并给出连接. https://blog.csdn.net/To ...

  9. uwp 沉浸式状态栏

    //隐藏状态栏if (ApiInformation.IsTypePresent(typeof(StatusBar).ToString())) { StatusBar statusBar = Statu ...

  10. [转]TensorFlow如何进行时序预测

    TensorFlow 是一个采用数据流图(data flow graphs),用于数值计算的开源软件库.节点(Nodes)在图中表示数学操作,图中的线(edges)则表示在节点间相互联系的多维数据数组 ...