Setting up a new mobile service is done through the Azure portal.
We're going to click New in the command
bar, select Compute > Mobile Service, and Create.
We're going to call our service Univ.
Azure Mobile Services will go out on the web and check for univ.Azure-mobile.net.
It appears to be available We're going to create a database,
and we're going to use the free 20 megabyte SQL database.
We also have
other options here to create a new SQL Server Database, if we want.
We're going to run this in West US region, hit Next,
we are going to create a new SQL Server database.
I am going to enter a name and a password.
You will also notice, we can configure advanced database settings if we want to.
For purposes of this demo, we'll just keep the defaults.
Azure is going to go ahead and create our mobile service.
And after about a minute or so, you'll
notice that the service is reporting Status Ready.
I have a URL available.
If I click on that URL, it'll take me directly
to the standard page that our service is serving up.
I'm going to hit Refresh a couple of times, so we generate some traffic.
And if we come back in, click on Univ and go over
to Dashboard, you'll notice we're already seeing some traffic to our service.
We have the capability
to monitor both API calls as well as Data Out.
If we scroll down to usage, you'll notice we've generated
seven Calls, and we have well over 16,000 Calls available still.
We have plenty of devices and data left.
If we move up, and I click on the
Data tab, you'll see we have no tables setup yet.
These tables are not table storage, which we'll cover later
in this course, but are in fact SQL Server tables.
I also have the capability to create a custom API to run a scheduler to do
Push notifications, Identity management, and Configure and Scale my service.
I will be covering all of this in additional details in a
course available on lynda.com called Up and Running with Azure Mobile Services.
In this course, we're going to stick to the
demo applications that area available here in the thundercloud.
I'm going to click on the thundercloud.
I'm going to select a Windows Store app, and
I'm going to click Create a New Windows Store App.
We already have Visual Studio Express 2012 for Windows
8 installed, so I'm going to click Create TodoItem Table.
This will go out and it will create a new table inside of SQL Server.
That table name will be the name of our service .todoitem.
So we will have univ.todoitem,
as a table in our SQL Server Database now. We're going to pick a language.
So I'm going to say, JavaScript, and click Download.
Let's go ahead and Save this.
Open it, Extract the files from the zip.
And we're going to open this with Visual Studio Express 2012 for Windows 8.
And you'll notice we have a reference
to a new JavaScript library called MobileServices.js.
If we want to investigate
what's inside that file, we can open
the js folder, and we'll see MobileServices.js.
This file is well documented, and you can go through the file
and see how all of the calls are happening to the cloud.
We're going to close this and we're going to scroll
down and look at the rest of the UI.
So you'll see there's a bunch of div tag here.
And we have the ability to insert a new to do item.
So this sample
application will be a task management application.
So you enter a bunch of to do items and
then you check off whether they've been completed or not.
So a very simple UI, a save button, and some text fields.
We also have a Refresh button.
If I open default.js, you will see this
is where we access the mobile services client library.
So I'm going to create a new varaible called client, I'm going to call into
my new mobile service, and my key has already been set up for me.
One of the really great things the team has done with mobile services, is give you
these starter packages that give you the capability
to instantly begin programming against your mobile service.
If you already have an application, you can go
back to the portal, and click Connect an Existing Application.
You'll get everything you need here to set up with both your key,
as well as how you can insert an item in the table.
If we continue to scroll down, we'll
notice, getting the table from Azure Mobile
Services is as easy as calling into the client library, and saying, get table.
I'm going to create a new BindingList.
So this is the WinJS control for a list view.
I'm going to call that TodoItems.
And then the rest of this is standard JavaScript WinJS calls.
Don't worry too much about this now.
If you haven't seen WinJS before or
Windows store development with JavaScript in HTML.
I'll be covering this in Up and Running with Azure Mobile Services.
For now, let's go ahead and run this on the local machine.
And you'll notice at the bottom we get a package restore is disabled by default.
Another great thing the team has done is rather than have a separate SDK that
you need to install for Azure Mobile Services.
It is as available as a nuget package.
So if I scroll up at the top, you'll see inside of my solution
I have a nuget config, but I haven't brought down any of those packages.
So if I go to the top and I say
Tools > Library Package Manager > Manage NuGet Packages for solution.
I'm going to get a message that says
some NuGet packages are missing from this solution,
click to Restore.
If I click Restore it will download all of
the latest bits for the Azure Mobile Services for WinJS.
I'm going to go ahead and click Manage, say OK, and then, Close.
Now when I run my application, I have all of the latest bits and
I have a sample UI for working with my University Windows Azure Mobile Service.
Let's go ahead an add a little sample data.
So we're going to go ahead and create
a service. We'll hit Save.
Then we'll connect to service, hit Save, and then Use Data.
Now, what's happening under the covers here is, this is a list
view whose source is going to rebind to all of this information underneath.
If I go ahead and click the check box, you'll see it's automatically refreshing.
We come back, and move down, You'll see my data source
is going to go ahead and rebind itself every time we
go ahead and refresh the items or if we update an item.
Let's go back to the portal and see how that data was set.
We're going to move up here to the top and click Data.
You'll notice I have one index and three records.
If we click on TodoItem, you will see we have
Create a Service, Connect to Service and Use the Data.
Create a Service has
its complete set to true.
So the UI for our, our JavaScript Windows Store App is no longer showing that.
I also have the ability here to look at
individual columns, set permissions, as well as run scripts.
I'm going to cover this in the next section of this chapter.
For now I want to point out that the
columns have been generated automatically for us using something called,
Dynamic Schema.
If we go back to our Windows Store App, if
we scroll down and we look at our buttonSave event listener.
You'll notice I have a, Insert TodoItem function, and its text is being set to
the textInput value, as well as complete, which is a bool value being set to false.
If we go to the definition, you'll see I'm actually inserting that entire TodoItem.
So
I didn't set any of the types.
Because as your mobile services is using Dynamic Schema, it'll
be able to pick up all of the language types.
So whether I'm using JavaScript, C# or another type of language,
it'll automatically convert what those types are into their SQL Server types.
Congratulations, we now have a running application up in Azure Mobile Services.
Next, we'll look at how we can start to log and
scale out that service.