>> Jeremy Foster: All right. I am going to... speaker for this evening, Nikola, welcome Nikola.

advertisement

>> Jeremy Foster: All right. I am going to go ahead and introduce our speaker for this evening, Nikola, welcome Nikola.

>> Nikola Metulev: Hi.

[clapping]

>> Nikola Metulev: Hi guys. I guess you can’t hear me. Oh, you can, okay.

So we are going to talk about building Windows store apps and we are going to use Windows Azure Mobile Services. Who here has actually used Windows Azure

Mobile Services or Azure in general? Who has been to the portal? Okay, so quite a lot of people actually, half of you. So my name is Nikola Metulev.

I am part of the Windows 8 Technical Evangelist here at corp. So I work, unlike Jeremy I actually stay here and he travels around the states. And that’s my alias and my e-mail and you can find me on Twitter. If you have any questions just do that.

So the agenda for today: we are going to talk about Windows Azure Mobile

Services. We are going to talk about how you can use Windows Azure Mobile

Services data, how to send Push Notification s, how to use auth, use the scheduler, and how to use diagnostics and scale. We are also going to a little coding. We are going to build an app and show you how you can actually interface your app with mobile services.

So what is “mobile services”? It was built to actually make it really quick for your mobile applications to connect to a backend service. So you don’t have to waste time. And you can push your apps really quickly to your customers. It provides a very easy way to store your data into Cloud and provides a very nice REST API on top of your data. So you can use that to communicate with mobile services. And actually we have a really nice STK for

Windows Store and Windows Phone 8, iOS apps if you are interested in that and

Android is also coming. Do you have a question? No, okay.

We give you an ability to write server logic, what we call server logic.

It’s actually a way to intercept the CRUD pipeline and enter your own business logic between all of the CRUD operations. So if you want to, on each insert in this table, if you want to send a Push Notification or send an e-mail you can easily do that with just having some JAVA script logic, server logic on your mobile services.

We are going to look into how you can do auth so you can prevent data access to only authorized users. And you can authorize users through Microsoft account, a Twitter account, a Google account and Facebook account. We are going to see how to do that as well.

Mobile services also give you a very easy way to send notifications to

Windows store applications, even Windows phone and iOS. The Windows store uses the WNS service. So you can easily send Toast notifications, Live

Tiles, Badge notifications, even Raw notifications. They recently just added a scheduler. So all your scripts that you are used to writing for all your

CRUD operations you can now write them to run on a specific time and even you can run them on demand. And you can do things like backing up your database on a specific time, sending e-mails, accessing remote services like Twitter and getting data from Twitter or RSS, etc. And I will show you how to do that as well.

We have a set of logging and diagnostic tools that we are going to go over so you can see how much you have used, how much data you have used, how much data you have pushed out, how much time you have used and you can log your, you can do some logging through your scripts. And then I will show you how to scale your applications. Scale them out and scale them up.

So key scenarios for Windows Azure: It was intended for a backend service to mobile applications. Currently we have STK’s for Windows Store apps, Windows

Phone 8 applications, iOS and Android is coming very soon. There have actually been a lot of people who have actually written their own STK’s because mobile services uses a rest API so they just build STK’s for Windows platforms.

And then we give you a lot of features that are already common for all your applications. So you don’t have to recreate notifications for you applications. You don’t have to recreate how to send Push Notification s on your service, mobile services just does that for you and I will show you how to do that really quickly. And then with rapid development you can create your applications, you can create your backend really quickly and push your application to the customer very quickly.

So I like to code, it’s why I love my job. I get to code a lot. So I am going to go in and show you, actually go to the Azure portal, and show you what the Azure portal looks like, how to create a mobile service, how to hook that up to your Windows data applications and how to actually send and receive data.

So let’s move onto our portal. So this is the Windows Azure portal. And here you can see we have the different services that Azure offers and right now I am in the mobile services tab. We currently have three mobile services. So to create a new mobile service I am simply just going to go to new and create. And you can give your name to the mobile service. So I just want to call it [indiscernible]. And that should be available.

And here, this allows you to hook up to an existing SQL database, or you can create a new SQL database on Azure. I already have a database, but if you don’t you can easily create a new SQL database. And this is one we created for you and you can set up a new user and password through this wizard.

Yes?

>>: Is it possible to hook up to table storage?

>> Nikola Metulev: Excuse me?

>>: Is it possible to hook up to Azure table storage?

>> Nikola Metulev: Yes, yes.

>>: Can you repeat the question?

>> Nikola Metulev: Oh yeah. The questions was is it possible to hook up to

Azure table storage?

>>: [indiscernible]

>> Nikola Metulev: And I am going to use an existing one. And let me just use my credentials. Okay, so that’s going to create an Azure Mobile Service.

The interesting thing here is you get with the free preview; you get up to 10 mobile services. And you can actually use one database for all your 10 mobile services. And the way Azure handles that is it creates a different scheme for each one.

So you can, for example, each one of your mobile services can have tables with the same name. And they can all exist on one database. And that’s good for if you don’t want to pay for multiple databases one Azure you can only have one for all your mobile services.

>>: Why would anyone need multiple databases? It can all be done on one?

>> Nikola Metulev: That’s the reason why you can all be on one. So you don’t have to pay for multiple databases, but if somebody wants to, let’s say add an application that’s really popular and they want to scale it out. Then they will create their own dedicated database and they can actually increase the database. And I will talk about that soon.

So our application has been, so our mobile service has been created. So I have created a database. I have hooked up to the database, created a REST

API on top of it. So this gives us a link that we can actually hit and talk to it. There is nothing there right now. We are going to add some data, but it’s live on Azure. So when we go inside we actually go to the getting started screen. And here you can see you can choose what platform you want to get started with. And Android is coming soon, but these are the three

STK’s we currently have.

And then you have an option of connect an existing store app or creating a brand new Windows store app. If you already have an app you want to connect you simply just follow these instructions and it’s very easy to get started within like 30 seconds. And today we are actually going to create a new

Windows Store app. So I am going to go through this.

So first thing you have to have Visual Studio 2012. I already have that.

You have to install the mobile services STK and that’s just a quick download and install. And I have already done that. And then second for this startup app we have to have Todoitem table in our database. So if I just press this that will just create the table for us. And it just goes to setup. So if we go back here and if we go to data we can actually see that we have a table called Todoitem. Let me go back.

And then here I can choose what language I want my application to be. For this startup it will only give you an option of C# and JavaScript, but if you are a native developer or VB developer the mobile STK actually supports all the languages. But for just getting started the application data you can get from here is only in C# and JavaScript. Since most of you are C# I think that’s appropriate we do C#, okay.

So let’s download this project. Let me extract it. And here we go. And I am going to open it in Visual Studio. So this project actually has already been set up for --. Our platform has already been hooked up to mobile services and we can actually run it right away. Let me run it and show you what it does. So it’s a simple Todo application. Oh, the resolution is too small. Okay I guess I have to go to higher resolution. Just give me a second. I think I have to go to the highest because that’s the two options

they gave me. I will increase the font for Visual Studio. Okay, let’s run that.

So it’s a very simple application. You have two columns. I can insert a

Todoitem. So I can say item one, save, item two, save and it automatically gets updated on the right column. You can see all my Todoitems. And if I want to complete it I simply complete and I can refresh the list. So it’s a very simple application you get off the bat. And all this data is already stored on mobile services. I will show you in a minute and let me show you the code first to see how everything works. So let me increase the font on here first real quick. Let me go to [indiscernible] and can you guys see this? Can anybody not see this?

Okay, so the first thing that you notice here in [indiscernible] what we have is we have this class, this reference to mobile service. It’s already been populated with a URI to the mobile service and also with our API key so we can actually attempt to [indiscernible] our mobile service. So that’s already been done for us. If you are starting with an existing app you will just copy this from the mobile service portal onto your app. So it’s a steady variable so you can use it throughout your app anywhere.

So let’s see how it’s been used on the main page of [indiscernible]. Oops that’s the wrong file. So the first thing we have a class of Todoitems. So this class will map to an item in our database. So it has two fields. It has a string, text and bullion which tell us if it’s completed or not. So it’s a very simple class. And then in our main page to [indiscernible] we have a reference to our table, actually mobile services. So we simply, to get this reference, we simply call app [indiscernible] with the item that we want and since we already defined the Todoitem above it.

And then to insert just a single Todoitem it’s only one line of code. We just simply insert the sync and we just pass the Todoitem. If we want to get an item or read an item also one line we can actually do some pretty interesting queries through link. So we can do, you know, I want the items that are not completed and this actually gets executed on the server. It’s not executing on the client so you only get the items that you want. And then to update an item also just one line, just call it update a sync. And then delete is not shown on here, but it’s also just one line, delete a sync.

Do you have a question? No, okay, sorry.

And let me show you what it looks like on Azure. So if we go to data and if we drill down to our table we can actually see that we have the two items that we just created. And it’s automatically done. And that was just a few lines of code and we already hooked up to mobile services. Okay, let me go back to our slides.

Okay, yes?

>>: [indiscernible]

>> Nikola Metulev: Yeah, you can have any different structure. I am going to talk about Dynamic Schema. That way it works, actually sorry, the question was: how do you create your own structure, how do you create your own class for mobile services?

You can create your class, and the way that Dynamic Schema works is when you send your class, your object to mobile services, it looks at all the fields of the adjacent object. It talks through adjacent. It looks at all the fields. It automatically translates that to your database and creates the column automatically as it needs to create them. And I will show you how that works soon. Okay, yeah.

>>: [indiscernible]

>> Nikola Metulev: How do auto create a database? How do you auto create a table? Yeah, so tables we want the developer to actually create them manually. We don’t want the tables to be generated dynamically. So each time, so if you notice before I downloaded my applications I pressed that create my Todoitem table. That automatically created this Todoitem table for me. If I wanted to create a new table I can just simply go here, give it a name and that will create another table. And then I have a class called table in my code that I can have in different kinds of fields.

Yes?

>>: [indiscernible].

>> Nikola Metulev: Yeah, so the Dynamic Schema is actually smart enough to just modify the database. It’s not going to remove any columns. So all the old items you have already inserted are going to stay the same. But if you insert a different item that you have changed the structure of Dynamic Schema will look in your item and dynamically create all the columns that it needs to for the new items that you have added; the new fields that you have added.

Any questions? Yes?

>>: Well, so for one I want to know if I saw this right. When you first created that database it had nothing in it, no columns?

>> Nikola Metulev: Yes, no columns.

>>: And then the columns were created as you ran the [indiscernible]?

>> Nikola Metulev: Exactly, yeah. And you can turn that Dynamic Schema on and off. Let’s just go here, sorry, configure, here we go. So you can go to enable Dynamic Schema. So if you turn that off and if you try to insert, let’s say an item that has fields that are not already created, columns in the database, it will just drop down and won’t insert it. It will just say,

“Sorry, I don’t know what this is. I can’t insert it into the table. I don’t have any columns for this”.

So this is useful when you are developing. So you can create this and turn it on. And when you release your application you can just turn it off. So if somebody gets a hold of your API key and tries to insert items you don’t want them to automatically create a bunch of different columns.

You had a question?

>>: I was wondering at this stage in the application the database has no notion of which user created it right?

>> Nikola Metulev: No not yet. So we are going to talk about auth soon. And

I am going to go back to my slides.

Okay, so I already talked about the different Schema that mobile services already creates. So you can have multiple mobile services on one same database. So if you have Mobile Service AppX and Mobile Service AppY, and if they both have the same table it just uses that schema to create both tables in the same database. And then if you want to manage your data yourself in

SQL it uses SQL Azure. So you can just go to the portal or the SQL portal, use SQL management studio and you can use the REST API. And there is a new

[indiscernible] tool that was just released where you can just create tables dynamically and so automatically you can do [indiscernible].

And then when we create in mobile services the REST API that is on top of our database [indiscernible] automatically so we already saw how that works. And

I already talked about Dynamic Schema so you can turn that on and off. So we can create also, what I am going to show you right now, is how to create the scripts that can intercept the CRUD pipeline. So you can add a script, your logic in between your CRUD operations. So on every insert if I want something to happen or some kind of logic; let’s say I want to send a notification to all my users, so I want to validate data, I can easily do that on mobile services and I will show you how to do that right now.

And then there are a lot of support modules that come when you want to create your business logic or your server logic. We have MSSQL so you can write queries, SQL queries directly on the serve. We have the request module so you can do an HTP request to some other services outside of your applications; so like Twitter API. You can do, we have the console module, which allows you to do a login. So you have console.warn, console.error. We have the Push module which allows you to do Push Notification s, or

[indiscernible] notifications. And then I will show you how to use that soon.

We have the table module which is very powerful acting and replaces the MSSQL module. You can do very rich JavaScript queries on all your tables and you can get different kinds of data from your table. You don’t even have to use

MSSQL. And then status codes are used to respond to any of your requests.

And that’s an actual MSSQL query. You can write it or you can use tables.

And actually you have got the table and say I just want these. So we don’t expect you to actually write this.

And then type mapping, we are still actually in preview. So we only have these types. So when they translate from JSON Values, all numeric values translate to Float. And then all Boolean values translate to a bit, DateTime values translate to DateTimeOffset and Strings translate to Nvarchar. And then we expect to add more types as the services grow and by GA we start to have a lot more.

Okay. So let’s add some server logic on our application so we can actually validate some data. I am going to go back to my portal. And I am going to go back to the data and drill into my cable, my Todoitem table. And if you notice on top there is a script tab. So if you go into script you can actually see all the different operations right there.

So you can have on each operation you can actually add your own logic. And so I want to do, on my insert operator request, I want to let’s say validate

the text on my Todoitem is more than 5 characters. So actually I have that over here. I hate coding on stage, here I go.

So basically we simply grab the item. We say if want the text to be less than 5 simply respond with a bad request and you can have a custom code. So say the text is too short. Otherwise go ahead and execute the operation and that will insert it into the table. So you can do operations before you have inserted something to check. You can do it after if you have inserted it.

So it gives you a lot of flexibility to do basic --.

>>: Is this JavaScript.

>> Nikola Metulev: This is JavaScript, yes.

[indiscernible]

Can everyone see this? Okay, so let’s go ahead and save this. So that’s it, it’s already live on Azure. So I am going to run the application again and let’s try to add an item that’s --. Actually let’s try and add an item that’s 5 characters and let’s add an item that’s less than 5 characters. And that crashed [indiscernible]. And you can see here, I am not sure if you can see it, but here we have our wire custom text that we said the text is too short. So you can handle this on the client side, but the validation actually happens on the service side.

Any questions? Yes?

>>: So for those who are not familiar with JavaScript is there like a collection of like, these are the columns validations that you need to do?

>> Nikola Metulev: Yes, if you go --. There is a really nice guide here, like for example if you click on here it’s going to give you how to use scripts. There are different modules you can use, modify the request and modify the response. There are a lot of actual examples that you can use.

And I think it’s actually pretty complete. It helps a lot.

Any questions? Yes?

>>: [indiscernible].

>> Nikola Metulev: There is some version of intelligence, but it doesn’t work that well. They expect that by the time this thing hits GA that it would actually be a lot better, but right now it’s not the greatest, no.

>>: When is GA?

>> Nikola Metulev: We don’t know.

Okay, so let’s go back to our slides. Let’s talk about Push Notification s.

Who here has actually used Push Notification s on Windows 8 apps other than

Jeremy? Okay, good.

So the way that Push Notification s work is what you see here in the green is what has actually been given to you already. So it’s already been created for you. And what you see in the blue is something that you have to do yourself. So you have to create the app yourself. And with mobile services you have to write the logic to actually send the Push Notification s. So the

way that Push Notification s work in general is that your application first of all has to request a channel URI from the notification Cloud platform.

This channel URI is unique to your application and that’s how WNS actually knows where to send this notification. So when you have this channel URI you actually send this to mobile services and mobile services stores the channel

URI so it knows where to send Push Notification s. So you are just register that like mobile services.

Yes?

>>: So that’s where all the [indiscernible]. So the channel URI is specifically application on the instance of that application?

>> Nikola Metulev: It’s specific to the instance; each URI is specific to the instance of your application. Your application has a package ID which is specific to the whole application. And when you request a channel URI you get one unique URI for each specific application. So the sample application on my machine will have a different channel URI than your application. Yeah, they are different.

And then when mobile services decides that it needs to send a Push

Notification either by a script that you have written or by a schedule script you have written it will attempt to get with Push Notification services. And

WNS service will say, “Hey, I need to send a Push Notification”. And it will tell it, “Hey, this is the channel URI that I want to send this notification to”. And then WNS will actually handle, take that and send it to your application. And then the notification Cloud platform will go ahead and render your Toast, or update the Live Tile or do whatever with the notification you have sent.

To do that with mobile services we actually, mobile services allows you to send Toast notifications, do Live Tile updates, do Badge updates and you can actually send Raw notifications if you wanted to. And then to authenticate with WNS services, I will show you how to do this. In Azure portal you have to enter your WNS credentials, your client secret and package SID so it knows how to authenticate in WNS. And then simply in your code you use the push names space. And actually this is, WNS is for the Windows Store, but you can actually use APS for IOS and for Windows Phone, just a different name space, to send Push Notifications.

And then here I will show you what kind of functions you can use here, but you can simply say send Toast text 01 and then it sends it for you.

>>: I have a quick question.

>> Nikola Metulev: Yes?

>>: Is there a [indiscernible]?

>> Nikola Metulev: Yes the WNS is just one service that comes, that’s

Microsoft.

So let’s go ahead and I am going to add a Push Notification. So each time we insert an item I want to send a Toast notification to each one of my applications that have been registered. So I am going to go back to my code.

I am going to, I need to create --. Sorry, so is everyone familiar with the portal here the Windows 8 application portal? Is anybody not familiar?

So this is where actually you submit your applications when you have created it. So you go here, you log in and you say I want to submit an app. And you do that and you say I want to --. So the first thing you have to actually give it a name. So this allows you to actually register your application name. And you need to do this in order to get a package ID in order to get notifications. So I am going to reserve this name.

So I don’t have to submit my application now and I just reserved my name so nobody else can take it. And I can keep that for a year. And this allows me to actually authenticate my application with WNS with a package ID. So this already gave me a package ID. And I can go back to visual studio. Oh, let me stop this from running.

Okay. And if I right click on my project I can just simply go to store and associate the app with the store. And I can just use my developer credentials. And this will give me a list of all the applications I have registered. Here is the one I just registered. And then this automatically will set up my package name, the package ID to what I have in the store. So it will automatically do all the work for me. So I don’t have to go to the package manifest and copy all these values my self. I just associate it and we are done on this side.

Then I need to go back to Azure and actually give it our credentials for push. So you can see there is a push tab right here. So you just need to provide your client secret and package SID so it knows where to send notifications and how to authenticate. To do that you will need to go to your Live portal for applications. Sorry, let me get the link for that. It was this one.

And here you can see all the applications you have registered. So I simply go to applications that I have just registered. I can go to edit settings,

API settings and I can see my client secret and my package SID right here.

So I just simply copy this. So this is just one thing. You have to just do this once to make sure you can authenticate. There we go and let me just save that. And we have dealt with that part.

So let me go back to my code and I am going to go through the three steps I have just talked about; that I need to request a channel URI and store that in my mobile services. So with my app, [indiscernible], each time I run the application, so in the on launch method I need to request a channel URI and then send that to mobile services. Now I have to have a way to store that in mobile services so I am going to create a new type called channel, so a new class. It’s very simple all it has is just a string of a URI and this is just a way to keep track of all the different URI’s. It’s just a way for mobile services to keep track of all the different URI’s, of all the app instances.

And then here I can just do a channel request. So what this does code, what this code does, sorry. Actually let me resolve all of these things. And of course I have to make this a sync because I am using a weight. So what we do here is first we just call Push Notification channel manager and we say,

“Hey, I need a channel URI can you just give me one”. And we store that in

CH.

And then here what we do is we create a new channel with that CH. We first check to see if we have already created one; if we have already sent one before. So we check our local settings on our machine and say, “Hey, has this application run before” basically. And if it hasn’t we simply say,

“Okay, insert the new channel ID into our new table”.

So I call mobile services get table. So I get the channel table, which I will create soon. I haven’t created it yet. And then I will simply say,

“Insert a sync to the new channel ID”. And then I store it in local settings so I know next time I run the application that I have already created a channel ID so I don’t have to insert a new one. And then if I have already created one and I have already pushed it to mobile services I simply update it with the new URI; URI’s update, they expire. So you have to make sure that each time you run the application you update it in your service or even better you can have a background service that does that for you.

So let’s go back to mobile services. I am going to go to data and I just need to create the channel table so we can actually store our channels. And

I am going to go inside and actually show you that this doesn’t have any columns right now. So I am going to go and say, “So you only have one column”. And we will see after I insert our first channel that it’s going to create the column itself.

Okay, so one last thing let’s add our script. So on the insert, each time we insert we want to send a Push Notification. And let me walk over this code.

So on insert we execute the request, so we insert the item first. And then on success we call the send notification item. So each time we insert an item we send a notification. And the send notification function grabs the channel table, so here we used the table module I mentioned before, and we just get an instance of the channel table. And then for each one of the channels that are in our table we simply call push.wns.sendtoastimage and text 03.

So who is familiar with Toast templates or Live Tile templates? Most of you are not, okay. So let me show you actually what I mean by Toast template 3 or 4, it’s confusing. If you go, if you search just search for Toast catalog or Windows 8 Toast catalog you can actually see all the different Toast types you can have. So here is the name for each one. So you can just see here, if I want one that has an image and has 3 lines or 3 strings, or if I just want one with no image. So you choose the right one you want.

And then mobile services I just call the Toast image in text 03. I give it the channel URI. I say, “Super awesome Todoitem inserted”. Here is text 2 and then I have an image that I have on block storage. I just give it the

URL. You can have image stored anywhere. And if that’s successful I log it.

If it’s not successful I just log an error. Let me just run that and let’s run our application one more time.

Okay. So we run the application and that grabs the channel URI and stores it in mobile services. And then each time I add an item now we should get a

Toast. There you go, super awesome Todoitem inserted. Yeah, you have a question?

>>: What is the limit, or the maximum number of Toast’s an app can send a day?

>> Nikola Metulev: I don’t think there is an actual limit to how many

Toasts’s you can send, there are three max you can show. So if you keep sending them three of them are going to show up, and then one is going to expire and a new one is going to show up. And then the user is going to go in and say, “Disable notification”. And you just basically annoy the user with notifications. Yeah, that’s not a good idea. The Toast notifications are meant for, I believe, only emergencies or for like rare occasions.

For just common notifications it’s easier to use Live Tiles. And I will show you how to do Live Tiles later also. But if you are not familiar with Live

Tiles, if you go to your start screen I am sure there are applications that just keep changing the data. I will show you how to do this on your application.

Yes?

>>: So in that example you are broadcasting to all your registered channels.

Do you have parameters that you have created to target specific users?

>> Nikola Metulev: Yes. I am going to talk about auth right now. And when they are authorized users, so they can authorize a different service, what you can do is you can capture that user ID. So you can keep track of which user ID and say, “Okay, this user ID is registered and wants to get notification for this one. So grab all the channels that are with this user

ID and send notifications to these channel URI’s”.

Yes?

>>: Do you have the code snippets file shared somewhere?

>> Nikola Metulev: There are actually a lot better code snippets online, if you go on windowsazure.com and it will show you the location where. But all these things I am showing you right now there are actually very simple similar examples online. I will show you where that is.

Okay, so let’s move on. What happened? Okay, oops not that. Okay, so let’s talk about auth actually right now. Mobile service allows you to provide authentication to a user through a Microsoft account, Facebook, Google or

Twitter. It gives you a table level permission for each one of the CRUD operations. So if you want to limit that you only want, on users that have authenticated with Twitter to insert an item, you can do that easily. And I will show you how to do that.

And then you can get more granular control by using the user low level modules and user ID module. For each one you can keep track of each one.

And you can say if this user is an admin allow them to do this. If not, you know, kick them out.

So let’s go ahead and add a Twitter authentication to our machine, to your application. So first what I need to do is when you create a new, when you -

-. If you want to allow users to actually log into a service you usually have to go through and create an application on that service. For example here on Twitter you have to create a Twitter application so you can get an

API credentials. And I have already done that before, but if you want to do it the instructions are on Azure. And it only takes about two minutes to do it and it’s free. It’s similar instructions for Twitter, Facebook, Google and Microsoft account.

So here what I need to do is when I go back to my Azure portal and I go to the [indiscernible] tab, it’s right next to the Push tab. And here you can see I can add all my application credentials here for each one of my, for each one of the providers. And right now I have Twitter so I am just going to copy the Twitter credentials real quick, copy the consumer secret and let me save that. And that’s it on this side, let’s save.

And then I am going to go back to my code and on my main page [indiscernible] each time I navigate on the page I want users to authenticate. So before I do that I actually want to show you what happens if I try to insert an item.

Actually I forgot one thing, sorry. If we go back to the portal I want to limit what users can actually insert an item.

So if I go back to my table of Todoitem I can go to permissions right here and I can say for insert permission. Right now it’s set to anybody with the application key. So anybody with this application they can insert items.

But if I just do a drop down I can say I only want authenticated users to insert items. And I can do the same thing with all the other operations.

This will not allow anybody to just insert an item.

So let’s save that and let’s start the application, which I already have.

And then let me add an item. And we say un-authorize. So we got an error un-authorize so this is something you have to handle in your code. So in order to get the user authorized we have to log them in. So what we simply do it’s one line of code. We simply say, oh wait let me add the sync. Here we go, so you simply say log in the sync and then you insert your provider that you want them to log in. But you can see there are all of the, well you can’t see them, but it says the first one is Facebook, Google, Microsoft account or Twitter. So you can choose which one and you can have multiple ones too.

So here I just did it with Titter and let me run this. So this was just one line of code to authenticate the user. So we run the application and it automatically takes us to Twitter to actually log in. So let me log in. And now I have logged in so let me add an item. And there you go the item has been added. And oh, we got a notification, thanks guy.

>>: What page did you add that [indiscernible]?

>> Nikola Metulev: I added that to the main page the [indiscernible], so on the on navigator method. So each time we navigated to the page or we started the application in this case, it executed this line saying, “Hey, log in the user. I want to authenticate the user”.

>>: So if you had previously authenticated would it pop up that dialog or would it just [indiscernible]?

>> Nikola Metulev: Right now it would ask you to log in again. It doesn’t persist the log in. So you have to keep logging in. There are ways to persist the log in, but they are more complicated.

Yes?

>>: If you had done this with a Microsoft account do you think, working with the credentials of the machine, would you then log in automatically or would you see this UI?

>> Nikola Metulev: You can, there are two ways. If you just simply create a

Microsoft account you can do it. It’s going to be the same way. You have to log in each time or you can use the Live STK in which case it grabs the credentials from the machine and just passes the token to mobile services and logs the user in as the user that’s logged into the machine. The first time you run it’s going to ask you if you want to give it permission and all that mumbo jumbo, but after that the user is going to be logged in.

Any questions? Okay, let’s move on. Yes?

>>: So can you use an authentication token later in your app for stuff that doesn’t have to do with data services? Like can you just use that as your authentication? And let’s say you wanted to do user specific things in your app that don’t relate to the service itself?

>> Nikola Metulev: Yeah, so basically when you authenticate you get a user ID and you can take this user ID and store it in your table. And when the user inserts you can grab this user ID and associate it with this item that got inserted. So you can keep track of which users insert which item, which users own what item, which users have registered what kind of service and you get the idea. You get to use, you can do whatever you want with the user ID.

And of course you can use it to get data from the service as well through your scripts.

Okay, let’s talk about scheduler. So scheduler was actually something that just got added about three weeks ago I believe. It allows you to run scripts on a schedule. So you can do it every like 15 minutes, or you can do it every third day of the month or you can do it on demand. And some of the examples, and this is a long list, but some of the better examples are you can periodically push data or even backup your database at a specific time.

You can pull and aggregate third party services like get Twitter Tweet’s or get RSS feeds. And you can load them into your database. You can do processing, like you can resize images, you can send Push Notifications, send e-mails and you can even send text messages. And there are a lot of examples on Azure.com where you can actually see how to do all those things.

So let’s go ahead and create a little schedule. I am going to go back to my

Azure portal, let me go back here. And go to the scheduler tab. And right now I don’t have anything so I am going to create a new schedule. And let me name this guy push pull Twitter. And I will set it to 15 minutes. I will let that create. Okay, so now it’s created, so let’s drill inside.

So we can see that it was never run and the next run is never since it hasn’t been enabled. And to enable it we just simply press the enable button. And then to run it on demand we can just say run once and it’s going to run it immediately. Right now if you go to a script tab you can see that it just has the default script [indiscernible]. If I run this it’s actually just going to add a log to the log. And here you go I can actually show you the log right now.

So if you go to logs you can see all the logs for all your services. And this is stuff I have done before, but this is the newest one. You can see you are running an empty scheduled job of this script for [indiscernible].

So that’s an easy way to de-bug your scripts.

So let’s go back to our scheduler and actually add our script. And I have the script here. So this script goes out to Twitter. Of course you have to remember to have the same name of your function as your scheduler. So this script goes out to Twitter and grabs the latest Tweet’s that have my handle as part of the Tweet and gives me only two of them.

So you can use Twitter API to do whatever. You can use any other services.

And then here for each one of the Tweet’s we call the set notification method. And the set notification method grabs each Tweet and then grabs the channel table. And for each channel it sends a Tile notification or a Live

Tile. So here we use the send Tile wide small image and text 04.

And similar as with the Toast, oh gosh wait, nope that’s the wrong thing.

And similar as with the Toast notification there is a whole catalog of these and it’s a lot bigger. So you can see there are a lot of different things you can send. I just spent an hour on that thing. And let me go back to

Azure. And for each one it just sends a Live Tile to our application.

Now I am going to save this. And before I run it in order to receive a wide

Live Tile, which I am doing here, my application will have to have a wide

Tile logo. And by default it does only have the small logo, the square logo.

So in order to receive the wide tiles I have to set up and add an image. So

I am going to go back to my manifest and simply just add an image here for my wide tile. I already have one; I just did this one in paint.

Here we go and let me run this application. Oh, I don’t want to log in right now. And, wait, Azure here we go. So let me run this script. And if we go back here, here is our application and then we see here is a Tweet that just popped up as a Live Tile.

And so if you notice I didn’t write any code to update the Live Tile. That’s a previous application I was testing this with. So I didn’t write any code on the Windows side, on the Windows client side to update the Live Tile and before I didn’t write any code to send Toast notification. This was all handled through WNS and the notification service this runs on Windows.

Any questions?

>>: Is it possible to [indiscernible]?

>> Nikola Metulev: Yes. If you, as I mentioned before, you have the console module. So you can say for example, I think it already has it here. No, but for each one I can just say console.logthisworks and if I run this, let me save it first, here we go. So I can go back here and then if you notice on top you have the logs at the end. So you can see all your previous logs each time you have done it. And the channel expired of course so I have older channels and the table. But here you say for each Tweet I have two channels

I just call this “worked”.

Any questions? No, okay, let’s go back to our earlier slides.

Let’s move onto diagnostic log and scale. For diagnostics we give you a very easy way to monitor your API calls. How many you have made, how much CPU time you have used and how much data you have sent out. You use, as I mentioned for logging, you have the console module so you can do errors, logs and warnings.

Scaling, so if your application gets popular and you need to scale it up you can scale it out to a dedicated VM. In the free mode you get it, it’s shared

VM. So you share a VM with multiple users, but if you want to have your own dedicated VM you can easily just purchase a VM and move your mobile services to that. And then you can scale it out to multiple instances. And then the same thing with your database; you can scale it out to your own database and then you can scale up to any capacity you want.

Okay let me show you that in the portal actually. So in Dashboard, if you go to Dashboard this is the diagnostic part. So I have done some API calls and things. So you can see actually here the red is the API calls. I have done

18 here, 18 there and then here I have used 2.58 seconds of CPU time sent out

40kB. And you can see some other information here. If you go to the logs I will show you this. You can see all the logs for your applications. So if something goes wrong, oh wait something went wrong, you can find out. I think it gives you a line of code and everything too. Not this one, but some of them do.

And then in scale, so this is where you actually scale up your application.

So right now it’s in free so that’s the default and you can move it to reserved. And here of course it says I have removed this pending limit on my account. You have to pay for VM’s. So you have to purchase your VM. And while it’s in preview mode it has a 33 percent discount just like websites.

So keep that in mind if you need to do that. And then here you can scale out your instances. Your max is three now, but that could increase.

And then for a database you can increase the size or you can scale it out to a larger size in your own --.

Yes?

>>: Does the [indiscernible]?

>> Nikola Metulev: I am sorry?

>>: If you have a large set of data will it all [indiscernible]?

>> Nikola Metulev: Unfortunately it doesn’t migrate the data when you move into your own dedicated database. So you have to probably write your own script at this point to migrate the data to any database.

>>: I think my question was a little bit different. I can send you an e-mail or something.

>> Nikola Metulev: I can talk to you after or something.

Any questions?

>>: Just really quickly [indiscernible].

>> Nikola Metulev: I am not actually really sure. I can ask somebody, but we will talk after.

Okay and then if you want to use mobile services it’s free. But if you don’t have any of these subscriptions for example you probably have to pay for the database. And the minimal database you can purchase is 100MB and that’s 5 dollars a month. But if you have one of these subscriptions you get

databases for free, so mobile services is free. And then here, I am sure most of you here have an MSDN account. So if you go to MSDN you can see you have 5 database units.

And here we go in summary. So we talked about how to connect the application to mobile services, how to store your data, how to write service scripts, authentication, how to send notifications, how to use the scheduler, diagnostic and data, logging, and data, diagnostics and how to scale your applications. Here are some useful resources, so windowsazure.com has a lot of good information. It has a lot of samples and a lot of tutorials that our team here has created and a lot of videos that you can go through.

If you have any questions you can use Twitter or our cloudnick, that’s one of the main guys on, oh sorry, in DP corp that actually deals with mobile services. So he would be a really good resource if you have any question about mobile services. Chris Risner is also a very good resource for if you write your application on IOS or Android. And demos are here and I can actually show you.

Here is the training kid which actually has a lot of good information about how to write your applications. Let’s go to Windows Azure and develop. And you have a lot of tutorials here and you can just go, “Hey, how do you do a

Push, how to do authentication, etc”.

Any questions? I think we are done right now. Yes?

>>: So back tot he authentication: you mentioned that the authenticated user gets an ID and I am imagining that the object you are storing in the table would have an ID property and you would set the ID property.

>> Nikola Metulev: What you can do is actually when you go to mobile services; and they way, the recommended way to handle that is, let me find it. Why is this not working? Okay, so the best way to do it --. If I go to data and let’s say I have a script, go to Todoitem. So on my insert script before I insert my item I can simply, sorry, script, insert. So let’s say I want to keep track of the user ID. So what I can do is I can just say item.userid and this creates a new field on my item. I can just say equals to user.id.

So the user item that you see up there is actually the authenticated user that sent and that has an ID. And I can just store the item. I can just create a new field on my item. And that will automatically create a new column that hasn’t been created. And you store the ID of each user.

>>: And then the read operations can be filtered by user ID.

>> Nikola Metulev: By user ID, yes. So you can say user ID is this. Even if you do it, if you want to do it on the service side on the read you can say for any request you can say only request these guys that have this user.

It’s going to pass to your user, say only the user that requested this only give them these objects.

Yes?

>>: Can you tell me a little bit about strategies for organizing your application. So for example if I have another line with a mobile service, but am also targeting one with a Windows 8 tablet, a Windows 8 phone and an

IOS, how best to kind of organize that and also match, for example, the

[indiscernible] part?

>> Nikola Metulev: Mask the scaling part?

>>: The [indiscernible], the UI part.

>> Nikola Metulev: Oh, the UI part. Yeah, mobile service --.

>>: [indiscernible]

>> Nikola Metulev: The STK, the mobile service STK for example Windows phone and Windows 8 is very similar. And you can put that in one same module that will communicate Windows Azure. However, for if you want to say the UI that will have to be separate for each one of your applications. So you can have a shared module for your mobile services for all your data for your back end stuff. But then the URI part would have to be done separately.

>>: My questions really is it the same? [indiscernible]

>> Nikola Metulev: No, so you have to keep track of the channel you arrive for each one.

[coughing]. Excuse me.

So when you send, for example, let’s say you send a channel URI for a Windows

8 application, you have to specify the destination for the Windows 8 application. And then when you store it in the table you just can have another filed that says this is a Windows 8 channel URI and this is a Windows channel URI. And then when you send notification you can use the different name spaces under push.

So you can do push.wns for Windows 8. So you can just check, okay is this a

Windows 8 URI? Send it to this; use this method. Is this a Windows phone

URI; use this method. It’s just an [indiscernible] statement basically.

>>: [indiscernible]

>> Nikola Metulev: Yes, yes, it uses the exact same thing.

>>: Okay, so that’s how it knows that it [indiscernible]?

>> Nikola Metulev: Yes, that’s exactly it. That’s just the API key. You can use it from any machine that it actually talks to by REST. So it uses REST

API’s and just passes that API key each time.

>>: So is there a way to say, for example, [indiscernible]?

>> Nikola Metulev: I am not sure. I will have to find out. So find me after and I will get you the information.

Yes?

>>: The channels don’t last forever right?

>> Nikola Metulev: No, yes they expire. So that’s the reason why each time we run the application we update the channel in our table to the most recent

one. So the most effective way you would want to do that is probably have a background service on Windows 8 that just runs occasionally and just grabs a new channel URI and then updates it in mobile services.

>>: [indiscernible]

>> Nikola Metulev: If you notice when I went to log --.

>>: [indiscernible]

>> Nikola Metulev: Basically you just have to do that on our client side. So you keep track if you have already sent your channel URI and your local settings. So I already showed how to do that, but I think if you go back here, so here I am saying, “Okay, have I already sent a channel URI”? And if

I haven’t I simply insert it. If I have then I update it. And the way I do that is that I use local settings. So if you haven’t used local settings, what local settings allow you to do is just, it’s sort of like a registry.

You say I want to key, I want to save this value under this key here in local settings.

And that’s persistent throughout your life cycle of your application. So if you close your application and open it up again this will stay after you have defined it. So if you already defined this you only have to update it. If you don’t find it, it’s the first time you have run it so you just push it.

And then you can have a scheduler job that actually goes through each one of your channel URI’s and checks if they have expired or not and then just purchase the [indiscernible] data.

>>: How do you check if it’s expired?

>> Nikola Metulev: Um, you just have to keep track. For example you can add here on my class I can add another field that just keeps track of when it was created. And channel URI’s usually expire after 30 days. So you can just check if it’s older than 30 days just go ahead and just push that data. If it’s expired there is not really a way, I don’t think there is, but I can find out, to actually check just by the URI. But that would just skip over it and it goes to the next one.

>>: [indiscernible]

>> Nikola Metulev: I am sorry, what’s the --?

>>: [indiscernible]

>> Can you repeat the question?

>> Nikola Metulev: Excuse me?

>>: Can you repeat the question?

>> Nikola Metulev: Yes, so the question is what’s the best way to store the user information on --? Are you talking about on mobile services or on the client?

>>: [indiscernible]

>> Nikola Metulev: It doesn’t ask me each time I insert an item. It asks me each time I start my application. So throughout my application it still keeps the user logged in. If you want to keep the user logged in throughout, if you want the log in to persist throughout your application there are ways to do it. It’s a bit more involved than I can do right now, but there are ways to do it. And I believe the only way to do it is with a Microsoft account at this point.

>>: And can you just automatically use the [indiscernible]?

>> Nikola Metulev: Yes, if you use the Live STK you can actually use that STK to log in the user. And then pass that token to the mobile service. And each time you boot up your application you can just grab that token and pass it to mobile servie and that will automatically log in the user. So you don’t even have to prompt the user. You only have to do that once.

Any other questions? Okay, so we are done here. So if you have any questions you guys can come up, but I think that’s the end of the public transmission.

Download