Eric lippert - Amazon Web Services
Eric lippert - Amazon Web Services
Eric lippert - Amazon Web Services
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
2. Before we can save the data, we need to add reference to<br />
‘Windows Azure Mobile <strong>Services</strong> Managed Client’. This is a simple<br />
wrapper to make HTTP calls easy for you. We already had it<br />
specified as a pre-requisite, so if you didn’t have it installed yet, go<br />
grab either from Nuget now and add reference to it in the project.<br />
You can get it from Nuget as follows<br />
Note the Mobile Service URL before clicking on the ‘Manage Keys’<br />
button<br />
5. Clicking on Manage Keys will give us a popup that shows us the<br />
Application Key and Master Key. We need only the Application Key<br />
for now.<br />
PM> Install-Package WindowsAzure.Mobile<strong>Services</strong> -Version 0.2.0<br />
Or if you install the VSIX, you can add a reference as follows<br />
3. To save data into the above table, we create a<br />
FakeTweetMessage class<br />
6. Posting Data to Azure Mobile Service<br />
a. In the App.xaml.cs insert the following code<br />
class FakeTweetMessage<br />
{<br />
public int Id { get; set; }<br />
[DataMember(Name = “myId”)]<br />
public string MyId { get; set; }<br />
[DataMember(Name = “fakeTweetText”)]<br />
public int FakeTweetText { get; set; }<br />
[DataMember(Name = “toId”)]<br />
public string ToId { get; set; }<br />
}<br />
4. Next we setup the Azure Client to talk to our Mobile Service.<br />
To do this, we first get the URL and the Application key from the<br />
Service Dashboard.<br />
public static MobileServiceClient MobileService = new<br />
MobileServiceClient(<br />
“https://zumofaketweetservice.azure-mobile.net/”,<br />
“Replace with the Application Key from Above”<br />
);<br />
b. In the MainPage.xaml.cs, we will introduce the following:<br />
private IMobileServiceTable<br />
fakeTweetMessages = App.MobileService.<br />
GetTable();<br />
c. Add a Button Click handler for the Send Message button as<br />
follows<br />
private async void SendMessageButton_Click(object sender,<br />
RoutedEventArgs e)<br />
{<br />
await fakeTweetMessages.InsertAsync(new FakeTweetMessage<br />
{<br />
MyId = MyIdText.Text,<br />
FakeTweetText = FakeTweetTextBox.Text,<br />
ToId = ToIdTextBox.Text,<br />
});<br />
}<br />
d. At this point, if we run the Application and provide some data<br />
in the Text Boxes and hit Send Message button, we’ll end up with<br />
data in our Azure Table as follows.<br />
76 | DNCmagazine www.dotnetcurry.com