我建个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. WPF入门(三)->几何图形之不规则图形(PathGeometry) (2)

    原文:WPF入门(三)->几何图形之不规则图形(PathGeometry) (2) 上一节我们介绍了PathGeometry中LineSegment是点与点之间绘制的一条直线,那么我们这一节来看 ...

  2. Adaptive partitioning scheduler for multiprocessing system

    A symmetric multiprocessing system includes multiple processing units and corresponding instances of ...

  3. TensorFlow 学习(四)—— computation graph

    TensorFlow 的计算需要事先定义一个 computation graph(计算图),该图是一个抽象的结构,只有在评估(evaluate)时,才有数值解,这点和 numpy 不同.这张图由一组节 ...

  4. WCF客户端C#代码 配置config文件

    不多说了,直接上代码吧.... 服务端Web.config文件中bindings配置 <bindings> <wsHttpBinding> <binding name=& ...

  5. WPF 小矢量图 : 主页,返回,加,减,文字按钮,左移,右移

    原文:WPF 小矢量图 : 主页,返回,加,减,文字按钮,左移,右移 代码:: <UserControl x:Class="SQ.TestPage" xmlns=" ...

  6. WPF 渲染原理

    原文:WPF 渲染原理 在 WPF 最主要的就是渲染,因为 WPF 是一个界面框架.想用一篇博客就能告诉大家完整的 WPF 渲染原理是不可能的.本文告诉大家 WPF 从开发者告诉如何画图像到在屏幕显示 ...

  7. c语言学习笔记(13)——链表

    链表 算法: 1.通俗定义: 解题的方法和步骤 2.狭义定义: 对存储数据的操作 3.广义定义: 广义的算法也叫泛型 无论数据是如何存储的,对数据的操作都是一样的 我们至少可以通过两种结构来存储数据 ...

  8. 使用Wireshark抓取SNMP Trap包

    Wireshark SNMP Trap 过滤关键字:snmp && udp.dstport == 162

  9. Why I Choose Delphi Summary

    Over the summer, there has been a number of blog posts on this topic, but I haven't seen a complete ...

  10. Linux性能测试 /proc目录

    /proc文件系统 - 各种内核信息/proc目录下文件提供了很多不同硬件设备和内核的详细信息.更多详情参见Linux kernel /proc.一般/proc例如: [root@SM155 proc ...