我建个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. 轮询方法FileSystemWatcher

    具体实现 FileSystemWatcher watcher = new FileSystemWatcher(WriteBackDir, "*result.txt"); watch ...

  2. 【物理】概念的理解 —— Phase(相位)

    Phase is the position of a point in time (an instant) on a waveform cycle. 相位指的是波形周期中点在某一时刻的位置.Phase ...

  3. WPF入门(三)->几何图形之线条(LineGeometry)

    原文:WPF入门(三)->几何图形之线条(LineGeometry) 前一章我们对wpf的xaml语言有了一定的了解,那么我们现在开始来学习如何使用wpf来画出几何图形. LineGeometr ...

  4. combobox添加选项

    如果不需要绑定字段,只需要显示列表 cmb_Type.Items.AddRange(new object[] {"姓名","年龄","性别" ...

  5. 一起学Python:网络通信过程

    1. 2台电脑的网络 image 说明 如果两台电脑之间通过网线连接是可以直接通信的,但是需要提前设置好ip地址以及网络掩码 并且ip地址需要控制在同一网段内,例如 一台为192.168.1.1另一台 ...

  6. python request get

    import requests from urllib import parse # 返回response resp = requests.get("https://www.baidu.co ...

  7. shell自动化下载、安装、配置nginx

    #!/bin/bash auto config nginx server #by author www.jfedu.net #2018年5月14日17:25:52 N_PAR="vim lr ...

  8. ue 不能初始化ftp组件

    进入到ue的安装目录下shift并右键-->在此处打开命令窗口,执行以下命令 regsvr32.exe wodFtpDLX.dll,如果是64位要执行regsvr32.exe wodFtpDLX ...

  9. 辨异 —— 行星 vs 恒星

    star:恒星,planet:行星: 1. 恒星 恒星是指宇宙中靠核聚变产生的能量而自身能发热发光的星体(比如太阳).过去天文学家以为恒星的位置是永恒不变的,以此为名.但事实上,恒星也会按照一定的轨迹 ...

  10. Running as a packaged application--- -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8000,suspend=n

    19.2 Running as a packaged application If you use the Spring Boot Maven or Gradle plugins to create ...