Azure Services - microsoft/uwp-shop-analytics-sample GitHub Wiki
[IN PROGRESS]
In order to get the demo up and running, you will need to register for the following Azure services and copy the appropriate keys in the ShopAnalyticsPCL\Resources\Keys.resx file. You will also need to publish the ASP.NET application to the Azure App Service.
- Azure App Service
- DocumentDB
- Azure Notification Hub
If you follow the below guide, you should be able to get all of the necessary cloud services up and running for this demo in an hour or less.
- Register for an Azure account (if you do not have one already)
- Create a new resource group for your Azure resources
- Create an Azure App Service
- Publish the ASP.NET application to your app service
- Create a DocumentDB account and database
- Create an Azure Notification Hub
If you do not already have an Azure account, head over to the Azure page to get started. At the time of writing, you get $200 of free credits to use when you register (more than enough to have this sample run for several months).
Once you have registered for you Azure account, head over to your Azure portal and sign in to begin. For now, just click "Resource groups" on the left side, and then select "Add". You'll be able to give your resource group a name and a location. Pick a location that is geographically near you for best latency. For name, choose whatever you like (I used "ShopAnalyticDocs").
Before you create an Azure App Service, first head to the Azure SDK downloads page and install the SDK for your version of Visual Studio (either 2015 of VS "15"). You will need this to easily publish the ASP.NET application to your App Service.
While that is installing, return to the Azure Portal. In your resource group, select "Add" and find "Web App" (Web App is another name for App Service). Click "Create" and give your "Web App" a name. Make sure you add it to your existing Resource Group that you just created. Finally, you will also need to create an App Service plan to host your App Service. Choose Create New and choose the option best suited for you (probably the cheapest one).
It will take a minute or two to deploy the newly created web app to your app service. When it is done, return to your resource group and navigate to the fresh app service. You should see something like the below:
Click to Copy the URL for the App Service, and in Visual Studio in the Keys.resx file, paste it as the value for the Resource with name "AzureWebAppUri".
Back in Visual Studio, right click on the "EventApi" project and select "Publish". For "Select a publish target", choose "Microsoft Azure App Service". Sign in with the same credentials used for your Azure subscription. Navigate to your newly create App Service and select Publish. You can leave everything else as the defaults.
A browser should launch with your new ASP.NET web application running!
You are going to have to publish once more (using these same steps) once you have all of the keys for the rest of the services added to the Keys.resx file, but the steps are the same and it should be fast now that the service is running.
Return to your resource group in the Azure Portal. In the resource group, select "Add" and search for "documentDB". Select "Azure DocumentDB" and choose "Create". Give you DocumentDB account an ID, add it to the existing resource group, choose a location (geographically nearest to you) and select "Create". The new account will deploy to your resource group in just a moment.
Return to your resource group so that the list of resources refreshes. You should now see the DocumentDB account. Select the new DocumentDB account, choose "Add Database" and give it an ID. Click on the newly created database and then select "Add Collection". Choose your pricing for the selection (Standard should be ~$24 USE/month unless you use the service a lot, but S1 will be a more consistent ~$25 USD/month - I chose S1 for my demo).
Once the collection is created, navigate to it in the Azure portal and select "Document Explorer". Select "Create" and give the document an ID of "eventDoc" and select save.
Finally, in Visual Studio, in the Keys.resx file, add the following values:
- DocDbCollectionName (which is the name of the collection you created)
- DocDbDocName (which should be "eventDoc" if you followed these instrucitons)
- DocDbKey (the primary key from your Azure DocDB account - see below for where to find this)
- DocDbName (the database name for what you created - this is one level above the collection)
- DocDbUri (the URI for your DocumentDB account - see below for where to find this)
To get the DocDbUri and the DocDbKey, navigate to your DocumentDB account in the Azure portal and select "Keys" (shown below)
To create an Azure NotificationHub you have to go to the Azure Management Portal. This is the old Azure portal but it has support for Azure NotificationHubs.
Navigate to the "Service Bus" section and create a new namespace. Make sure to select type "Notification Hub". Make sure to set the region to something geographically near you. It should look similar to the below.
The service bus namespace will be the container for the NotificationHub. After the namespace is created, navigate to it in the Azure Management Portal and select "New" and then "Notification Hub". Click "Quick Create" and give the Notification Hub a name.
Click on the new notification hub and click on "Configure". In the configuration, you will need to pass in a package SID and a client secret for your UWP application. In order to obtain these values you must associate the application with a product in the Windows Store. First make sure you have already signed up for a developer account at the Windows Dev Center.
Once that is done, you can right click on "DataClient" (the project) in Visual Studio Solution Explorer. Navigate to Store -> Associate App With The Store... and sign in with your new dev center account. You can reserve an app name or pick an existing app name.
When the association is complete, you need to return to the Windows Dev Center and sign in to your account. Navigate to your app dashboard and find the app that you associated your project with.
When you look at the App overview, you will see a "Services" button the left hand side.
Click on "Services" and select "Push notifications". Click on the "Live Services site" link which will then display the Package SID for Windows Store as well as the Application Secrets.
Return the Azure Management Portal for the Notification Hub Configuration settings and copy over Package SID and Application Secret into the respective fields (shown below)
Make sure there are no additional white spaces after you paste the values in.
Now that the hub and application are all setup, all you need to do is add the appropriate values into Keys.resx.
For NhNamespaceName, add the name of the Notification Hub namespace from the Azure Management Portal (not the name of the notification hub itself). For "NhListenConnection", get either the Primary or Secondary Key for "DefaultListendSharedAccessSignature" in the Azure Management Portal for the Notification Hub configuration. For "NhFullConnection", get either the Primary or Secondary key for "DefaultFullSharedAccessSignature".
If that was a lot of information, a helpful video can be found at the blog here.