35. コード
▷テーブル構造と同じ構造のクラスを用意
▷
Public Class COD2013Context
Public Property ID As Integer
Public Property Item As String
End Class
Public Shared MobileService = New MobileServiceClient(
"https://hatsune.azure-mobile.net/",
"CxxxxxxxxxxxxxxxxxxxGRhjhCBe71“
)
Private AnswerTable As IMobileServiceTable(Of COD2013Context) =
MobileService.GetTable(Of COD2013Context)()
Public Async Sub InsertAnswerItem(item As COD2013Context)
Await AnswerTable.InsertAsync(item)
End Sub
42. ASP.NET MVC 4 - Model
▷データ構造を定義したクラスを用意
▷データ取得用クラスを用意(ここでDBアクセス)
Public Class COD2013Context
Public Property ID As Integer
Public Property Item As String
End Class
Public Class TResult
Public Property Items As COD2013Context()
End Class
43. ASP.NET MVC 4 - Controller
▷コントローラにコード実装
▷http://……/api/Values
Public Class ValuesController
Inherits ApiController
Private Model As New COD2013Model
' GET api/values
Public Function GetValues() As TResult
Return Model.GetValues()
End Function
End Class
47. Windowsストアアプリから接続
Public Async Function GetAnswerItem() As Task
Dim urlString As String = String.Format(SearchUrl,
Date.Now.ToString("yyyyMMddHHmmss"))
Dim client As New HttpClient
Using response As HttpResponseMessage = Await client.GetAsync(urlString)
Dim responseDataStream As Stream = Await response.Content.ReadAsStreamAsync
Using stream As New MemoryStream()
responseDataStream.CopyTo(stream, responseDataStream.Length)
stream.Position = 0
Dim serializer As New System.Runtime.Serialization.Json.DataContractJsonSerializer(GetType(TResult))
Dim jsonDataValue As TResult = CType(serializer.ReadObject(stream), TResult)
Me.Items = New ObservableCollection(Of COD2013Context)(
From venue In jsonDataValue.Items
Select New COD2013Context With
{
.ID = venue.ID,
.Item = venue.Item
})
End Using
End Using
NotifyPropertyChanged("Items")
End Function