34
Microsoft Azure Mobile Services 概概概 Xamarin 概概概概 概概 概概概 概概概概概概概概概概概概概 概概概概概概概概概概概概概 概概概概概概概概概概概概概概 & 概概概概概概概概概概概概 http://blogs.msdn.com/b/shosuz/

Microsoft azure mobile services 概要と xamarin との連携

Embed Size (px)

DESCRIPTION

2014/6/27(金) 日本マイクロソフトで行われた インフラジスティックス・ジャパン様、エクセルソフト様、との共同セミナー "C# を使い倒す!クロス プラットフォーム アプリ開発とクラウド連携の新潮流" のMobile Services セッションの資料です。

Citation preview

Page 1: Microsoft azure mobile services 概要と xamarin との連携

Microsoft Azure Mobile Services 概要と Xamarin との連携  

鈴木 章太郎テクニカルエバンジェリスト日本マイクロソフト株式会社デベロッパーエクスペリエンス & エバンジェリズム統括本部http://blogs.msdn.com/b/shosuz/

Page 2: Microsoft azure mobile services 概要と xamarin との連携

テクニカルエバンジェリスト http://blogs.msdn.com/b/shosuz 

Microsoft Technology Center アーキテクト http://www.microsoft.com/ja-jp/business/mtc/ads.aspx 

中央大学 総合政策学部 非常勤講師、   東京工業大学大学院 非常勤講師

経済産業省・ IPA 情報連携用共通語彙基盤 プロジェクト委員

Microsoft 軽音楽部 広報担当( Guitar/Keyboard )

Page 3: Microsoft azure mobile services 概要と xamarin との連携

Microsoft Azure Mobile Services 概要ASP.NET Web API バックエンド

オフラインサポートMicrosoft Azure Active Directory 連携

アジェンダ

Page 4: Microsoft azure mobile services 概要と xamarin との連携

Mobile Services 概要

Page 5: Microsoft azure mobile services 概要と xamarin との連携

MBaaS : Mobile Backend as a Services

データベース

バックエンドの共通化

認証 プッシュ通知

スケール マルチデバイス

モバイルアプリに迅速にクラウドバックエンドを追加

Page 6: Microsoft azure mobile services 概要と xamarin との連携

Mobile Services 最新機能を含む全体像

プッシュ通知

データベース

ユーザー認証

バックエンド

Node.js Express

ASP.NET Web API

SQL Table Storage

Blob Storage

WNS & MPNS

APNS GCM

Mongo DB

Notification Hubs

ソース管理

Facebook

Twitter Microsoft Google Azure Active

Directory

Windows ストアiOSAndroid XamarinPhoneGapSencha

Windows PhoneiOSAndroidHTML 5/JS

クライアントSDK

Hybrid Connections

RE

ST A

PI

Page 7: Microsoft azure mobile services 概要と xamarin との連携

はじめての Mobile Services

Xamarin + Node.js バックエンド

Demo

Page 8: Microsoft azure mobile services 概要と xamarin との連携

ASP.NET Web API バックエンド

Page 9: Microsoft azure mobile services 概要と xamarin との連携

データモデル( EF-CodeFirst )、スケジュールドジョブ Visual Studio のツールを最大限活用 ローカルとリモートでデバッグ、発行

ASP.NET Web API バックエンド

ソースコード

Mobile Services 互換 Web API コントローラー

Git

Web 発行

Commit hook: ビルドプロジェクト

WebsiteXDRIVE\site\wwwroot

Mobile Servicescompatible WebAPIcontrollers

Web.config

C:\...\MobileServices

Mobile Servicesruntime

Web.config

website root

   ユーザーDB:EF CodeFirst またはカスタムマイグレーション埋め込まれた    App settings

Load

Page 10: Microsoft azure mobile services 概要と xamarin との連携

Mobile Services

.NET バックエンドによるCRUD 処理の実装とデバッグ

Demo

Page 11: Microsoft azure mobile services 概要と xamarin との連携

Xamarin との連携

Page 12: Microsoft azure mobile services 概要と xamarin との連携

Xamarin の特徴

“ フル” ネイティブすべての API が使える

パフォーマンス高コンパイル済パッケージ

C#, .NET , Visual Studio既存資産やスキルを活用

iOS

Android

Page 13: Microsoft azure mobile services 概要と xamarin との連携

13

PCL ( Portable Class Library )

ビジネス ロジック C#

Visual Studio with Xamarin

複数の .NET 処理系に対して、バイナリレベルで再利用できるライブラリネイティブ

Page 14: Microsoft azure mobile services 概要と xamarin との連携

14

PCL の仕組み

ユーザインターフェース機能の具体化依存コード

ユーザインターフェース機能の具体化依存コード

ユーザインターフェース機能の具体化依存コード

ロジック・データ・抽象化された機能

参照 参照 参照

Page 15: Microsoft azure mobile services 概要と xamarin との連携

15

Xamarin Component Store

追加コンポーネントで簡単機能追加

Page 16: Microsoft azure mobile services 概要と xamarin との連携

16

Storyboard / XIBAndroid Designer

ネイティブAXMLBlendBlend

MvvmCross

ViewView View

ViewModel

PCL( Portable Class Library )Model

Page 17: Microsoft azure mobile services 概要と xamarin との連携

オフラインサポート

Page 18: Microsoft azure mobile services 概要と xamarin との連携

エンタープライズモバイルアプリのデータ利用シナリオ

オフラインデータ操作

・ローカルテレメートリーデータ・分散数値計算処理、等々…

・ワークフロー・ユーザー入力 / 更新

Table Controller

デバイス

SQLite

Database

Mobile Services

Push/Pull

Page 19: Microsoft azure mobile services 概要と xamarin との連携

データベース作成とテーブルの定義・MobileServiceSQLiteStore ・データベース作成と テーブル作成を wrap・ Client /Server 双方に作成  - オフラインデータ用クラス・標準的な SQL DDL は不要

データベースの作成

テーブルの作成

Page 20: Microsoft azure mobile services 概要と xamarin との連携

オフラインサポートの実装 Demo

Page 21: Microsoft azure mobile services 概要と xamarin との連携

Microsoft Azure Active Directory 連携

Page 22: Microsoft azure mobile services 概要と xamarin との連携

Microsoft Account, Twitter, Facebook, Google ID Microsoft Azure Active Directory 各 CRUD 操作へのアクセス許可の設定方法

サーバーサイドスクリプト( Node.js )コントローラーの各メソッド( .NET )

認証

Page 23: Microsoft azure mobile services 概要と xamarin との連携

Azure Active Directory と Mobile Services 組織 ID 利用モバイル LOB アプリ開発

可能 Microsoft Azure Active Directory ユー

ザー

Page 24: Microsoft azure mobile services 概要と xamarin との連携

Active Directory Authentication Library (ADAL)Microsoft Azure Active Directory によっ

て保護されたリソースへのログインを可能に

複数の企業リソースへのシングルサインオンを提供

Windows ストアアプリ、 iOS/Android アプリ

各プラットフォームで利用可能

Page 25: Microsoft azure mobile services 概要と xamarin との連携

1) クライアントアプリが ADAL を使ってログインを試行。ユーザーが入力したクレデンシャル情報を Azure AD に送信

2) Azure AD は Mobile Services のためのアクセストークンと   リフレッシュトークンのペアをADAL に返送

3) クライアントは、当該 アクセストークン を Mobile Service に 渡し、 Mobile Services トークンに変換して、セッションを継続

基本的な ADAL + Mobile Services のフロー

3

2

1

Page 26: Microsoft azure mobile services 概要と xamarin との連携

string authority = “https://login.windows.net/< テナント名 >.onmicrosoft.com”;string resourceURI = “https:// サービス名 .azure-mobile.net/login/aad";string clientID = “<Azure Active Directory ポータルから入手した Client App ID>";

AuthenticationContext ac = new AuthenticationContext(authority);

AuthenticationResult ar = await ac.AcquireTokenAsync(resourceURI, clientID);

string accessToken = ar.AccessToken;

// Mobile Services にアクセストークンを付与

JObject payload = new JObject();

payload["access_token"] = accessToken;

MobileServiceUser user = await

App.MobileService.LoginAsync(

MobileServiceAuthenticationProvider.

WindowsAzureActiveDirectory, payload);

基本的な ADAL + Mobile Services のフロー

Page 27: Microsoft azure mobile services 概要と xamarin との連携

Active Directory 連携による Mobile Services アプリ認証 Demo

Page 28: Microsoft azure mobile services 概要と xamarin との連携

DevicesOffice 365 ※

認証

予定更新

Microsoft AzureMobile

Servicesデータ更新

など

Database

SQL Azure Database と Exchange Online の予定表の双方にイベントを追加

※ Mobile Services により ID プロバイダー部分以外は全て共通ロジックで 実装可能

Page 29: Microsoft azure mobile services 概要と xamarin との連携

1) Mobile Service がリソースの URI と Client ID / Client Secret つきで、アクセストークンを Azure AD に送信

2) Azure AD はリモートリソースのためのアクセストークンとリフレッシュトークンのペアを返送

3) Mobile Service がログイン済ユーザーを代行してリモートリソースとコミュニケート

拡張シナリオ : リソースへのログイン代行

1 2

3

Page 30: Microsoft azure mobile services 概要と xamarin との連携

ServiceUser user = ( ServiceUser ) this.User;

AzureActiveDirectoryCredentials creds = (await user.GetIdentitiesAsync())

.OfType<AzureActiveDirectoryCredentials>()

.FirstOrDefault();

string accessToken = creds.AccessToken;

string authority = “https://login.windows.net/ テナント名 .onmicrosoft.com";

string resourceURI = "http://myresource";

string clientId = “b69ee3c9-c40d-4f2a-ac80-961cd1534e40“ ; //Mobile Services から取得

string clientSecret = “oF2LC0pLyfwvUwT61/oVUJ+U8AuwTu+Lyorzt3yZTtE=“ ; //Mobile Services から

AuthenticationContext ac = new AuthenticationContext (authority);

AuthenticationResult ar = ac.AcquireToken(resourceURI, new UserAssertion(accessToken),

new ClientCredential(clientId, clientSecret));

string resourceToken = ar.AccessToken;

拡張シナリオ : リソースへのログイン代行

Page 31: Microsoft azure mobile services 概要と xamarin との連携

Active Directory 連携による Mobile Services ( SQL )と Exchange Online への同時書き込み

Demo

Page 32: Microsoft azure mobile services 概要と xamarin との連携

Xamarin + Mobile Services でパワフルにアプリ開発!

プッシュ通知

データベース

ユーザー認証

バックエンド

Node.js Express

ASP.NET Web API

SQL Table Storage

Blob Storage

WNS & MPNS

APNS GCM

Mongo DB

Notification Hubs

ソース管理

Facebook

Twitter Microsoft Google Azure Active

Directory

Windows ストアiOSAndroid XamarinPhoneGapSencha

Windows PhoneiOSAndroidHTML 5/JS

クライアントSDK

Hybrid Connections

RE

ST A

PI

Page 33: Microsoft azure mobile services 概要と xamarin との連携

Microsoft Azure Mobile Services  http://azure.microsoft.com/ja-jp/services/mobile-services/  チュートリアル  http://azure.microsoft.com/ja-jp/develop/mobile/ 講演者ブログ  http://blogs.msdn.com/b/shosuz/

リソース

Page 34: Microsoft azure mobile services 概要と xamarin との連携

© 2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.