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 ...
随机推荐
- svn X在Xcode中使用
1 在终端输入命令:清除以前的svn链接地址( /Users/mac/Desktop/SHiosProject/SVNmangerfiles) nie-xiao-bo-mac-pro:~ mac$ s ...
- np.max 与 np.maximum
1. 参数 首先比较二者的参数部分: np.max:(a, axis=None, out=None, keepdims=False) 求序列的最值 最少接收一个参数 axis:默认为列向(也即 axi ...
- hibernate annotation 相关主键生成策略
Hibernate 默认的全面支持 13 物种生成策略 : 1. increment 2. identity 3. sequence 4. hilo 5. seqhilo 6. uuid 7. uu ...
- SharePoint 2010/2013 隐藏的速度下拉菜单列表项
SharePoint 2010/2013 隐藏的速度下拉菜单列表项 有时为了防止一些用户编辑列表项.需要隐藏下拉菜单列表项.,仅仅须要添加一个内容编辑器控件,将css代码写入其HTML ...
- ckplayer 插件在线视频播放
1. CKplayer 它是一款用于网页上播放视频的插件,支持的格式有:http 协议上的 flv, f4v, mp4格式,同时支持 rtmp 视频流格式播放.使用非常简单. <html> ...
- js父窗体关闭,子窗体紧随
近来的.我们遇到了权限管理系统.由于权限管理系统与原系统的风格不符.打开一个全新的窗口.问题就来了.admin取消后,,权限管理形式不关闭.其他普通用户登录后.尚能经营权的管理形式. 简化问题:adm ...
- WPF的消息机制(一)- 让应用程序动起来
原文:WPF的消息机制(一)- 让应用程序动起来 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/powertoolsteam/article/det ...
- 使WPF程序应用预置的控件风格, 如Aero, Luna, Royale, Classic等
原文:使WPF程序应用预置的控件风格, 如Aero, Luna, Royale, Classic等 WPF预设有Aero, Classic, Luna, Royale主题, WPF程序会根据 ...
- 对scrollTop的研究
本文主要从原生 JS以及jquery来说明scrollTop是如何实现的,以及一些技巧,以及在PC端和移动端使用的差异. 首先用代码表示下如何回到顶部的简单原理 <!doctype html&g ...
- python 教程 第九章、 类与面向对象
第九章. 类与面向对象 1) 类 基本类/超类/父类被导出类或子类继承. Inheritance继承 Inheritance is based on attribute lookup in Py ...