Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
在 app 的開發中,我們常會在網路上建立網頁應用程式或是網站 API 來將資料儲存在雲端,如此一來,使用 app 的人,除了重新安裝 app 也能存取得到原本儲存的資料之外,若是在不同裝置上使用同一個 app 也能夠存取相同的資料。而對開發人員而言,更能夠因為資料與 app 各自獨立,能更容易在其它的平台利用這些資料再做應用及服務。
這篇文章將會介紹如何運用 Windows Azure 所提供的 Mobile Service 來輕易地完成一個「雲端化」的記帳 app 開發。
建立 Windows Azure Mobile Service 服務
由於目前 Mobile Service 在 Windows Azure 上還是預覽服務,所以已經有 Windows Azure 訂閱帳戶的話,可以直接至預覽功能的頁面申請試用,稍待一段時間等待認證通過時便可以立即使用,如此便能夠開始建立 mobile service app。Windows Azure Mobile Service 目前先推出 Windows 8 的支援,未來也將會支援更多的應用程式平台 (如:Windows Phone、iOS 及 Android 等)
首先點下 Create new app 建立一個 mobile service app:
接下來就是填寫 mobile service app 的相關資料,包括最重要的 domain name,系統會檢查名稱是否可用,設定這個欄位也是確定這個服務的 URL,同時也可以建立及設定儲存資料的資料庫:
在服務建立完成後,就可以在 dashboard 上看到直接產生 Windows 8 app 的範本,或是教學如何在既有的 Windows 8 app 上使用 Windows Azure mobile service,但不論是要使用產生的範本,或是在既有的 Windows 8 app 上連接這個服務,都建議先安裝 Mobile Service SDK,這樣便能以較容易的方式連接到服務上來操作:
接下來,為了我們之後要完成的記帳 app 先來建立一個 table 用來儲存資料,Windows Azure Mobile Service 所提供的 table service 是一種 NoSQL 的資料儲存架構,所以不必在此時設計 table schema:
table 建立完成後,就可以先回到 app 開發的部份。
開發 app
在建立好 Windows Azure Mobile Service 上的 service app 之後,也將 Windows Azure Mobile SDK 安裝完成後,就可以開始開發 Windows 8 app 來運用這個服務了。
在建立了一個 JavaScript 的 Windows Store app 後,首先在專案視窗中的 References (參考) 按右鍵選擇 Add References... ,然後將 Windows Azure Mobile Service 勾選起來:
接著,別忘了在 default.html 中加入 Windows Azure Mobile Service 的 JavaScript 檔案:
如此便能利用下列程式碼的方式來 insert 一筆資料到 mobile service app 中的 table:
這樣一來,mobile service app 中的 table 就會根據你塞入的資料來儲存了:
從這個簡單例子的示範,是不是覺得製作一個「雲端化」的應用程式突然變得很簡單了呢?趕快申請 Windows Azure 服務,來開發各式各樣的 app 吧!