Windows Azure之Mobile Service
我建个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的更多相关文章
- [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 ...
- 跟我学Windows Azure 四 Cloud Service中的WebRole与WorkRole,及他们之间的通信
Cloud Service 中WebRole就相当与我们的WebSite,而WorkRole相当与我们在服务器上写了个Windows Service,站在高可用的角度上来讲,Cloud Service ...
- [iOS]使用Windows Azure來做iOS的推播通知 (转帖)
這一篇我們用Windows Azure 的Mobile Service 來實作iOS的推播通知,底下我們分成三個階段來探討如何實作推播通知的服務: 第一階段: 開啓你的Windows Aure服務 ...
- Windows Azure Service Bus Topics实现系统松散耦合
前言 Windows Azure中的服务总线(Service Bus)提供了多种功能, 包括队列(Queue), 主题(Topic),中继(Relay),和通知中心(Notification Hub) ...
- Windows Azure Service Bus Notification Hub推送通知
前言 随着Windows Azure 在中国的正式落地,相信越来越多的人会体验到Windows Azure带来的强大和便利.在上一篇文章中, 我们介绍了如何利用Windows Azure中的Servi ...
- Windows Azure Service Bus (1) 基础
<Windows Azure Platform 系列文章目录> 我们在基于Windows Azure进行云端开发的时候,云端的软件通常都需要与其他软件进行交互.这些其他软件可能包括其他In ...
- windows azure Vm、cloud service、web application 如何选择可用的服务
windows azure 的web应用和虚拟机都经常用.我们经常把我们的网站部署上去.一般选择web应用或者开一个虚拟机.开一个虚拟机就会按照虚拟机的使用时间进行计费. 那么我们选择web部署在哪里 ...
- [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 ...
- [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 ...
随机推荐
- RPC与REST的差别
一:RPC RPC 即远程过程调用, 非常easy的概念, 像调用本地服务(方法)一样调用server的服务(方法). 通常的实现有 XML-RPC , JSON-RPC , 通信方式基本同样, 所不 ...
- 在erlang项目中使用protobuf
在erlang项目中使用protobuf http://blog.csdn.net/mycwq/article/details/21864191 protobuf是google的一个序列化框架,类似X ...
- erlang app 文件
http://hje.iteye.com/blog/1211734 应用的概念¶ 当我们写了实现特定功能的代码之后,我们可能想将代码转成一个 应用 (application),这是可以作为一个单元启动 ...
- Java数组定义学习的一些随笔
//一维数组的定义 int[] arr1 = new int[3];//arr1 = {1,2,3}: 错误 int[] arr2 = new int[]{1,2,3};//int[] arr2 = ...
- Qt多线程和GUI界面假死(run()是线程的入口,就像main()对于应用程序的作用。分析QThread::exec函数的源码,旧的QMutexLocker模式其实很好用,挡住别人进入抢占资源,可照抄)good
QThread的常见特性: run()是线程的入口,就像main()对于应用程序的作用.QThread中对run()的默认实现调用了exec(),从而创建一个QEventLoop对象,由其处理该线程事 ...
- Android菜鸟的成长笔记(18)——绑定本地Service并与之通信
在上一篇中介绍了Service与Activity的区别及Service两种启动方式中的第一种启动方式startService(). 我们会发现用startService().stopService() ...
- Arcgis api for javascript学习笔记(4.5版本) - 点击多边形(Polygon)并高亮显示
在现在的 arcgis_js_v45_api 版本中并没有直接提供点击Polygon对象高亮显示.需要实现如下几个步骤: 1.点击地图时,获取Polygon的Graphic对象: 2.对获取到的Gra ...
- 在WPF窗体中重绘
原文:在WPF窗体中重绘 写这篇主要是为了验证任何元素自身都具备绘图功能. 在默认Window中重写OnRender方法 protected override void OnRender(Draw ...
- Android中使用sqlite3操作SQLite
SQLite库包含一个名字叫做sqlite3的命令行,它可以让用户手工输入并执行面向SQLite数据库的SQL命令.本文档提供一个样使用sqlite3的简要说明. 一.创建数据库: 1.将sqlit ...
- Matlab Tricks(十八)—— 矩阵间元素距离的计算
两个矩阵间元素(向量)距离的度量,首先想到的是遍历,循环的方式,显然 matlab 下的编程并不推荐,matlab 下矩阵向量化编程效率尤高. 先考虑两个向量距离的计算: ∥x−y∥2=∥x∥2+∥y ...