Windows Phone 7 Development : Building a Phone Client to Access a Cloud Service (part 5) - Deploying the Service to Windows Azure
By deploying to Windows Azure, you will have a redundant, fault-tolerant service that you can scale out if you need to meet the demands of heavy usage. You will learn how simple it is to configure the service and deploy.
8.1. Preparing for Windows Azure NotepadService
You will be creating a Windows Azure service host in order to deploy WCF NotepadService to a Windows Azure platform.
8.1.1. Signing Up for Windows Azure and Creating a Project
Open the browser of your choice.
Go to www.microsoft.com/windowsazure/ to sign up and buy the Windows Azure service account. Follow the directions provided by Microsoft in order to purchase and acquire the service account in order to continue with the following steps.
Go to https://windows.azure.com/ and sign in using the account you created in Step 1.
8.1.2. Connecting to the Windows Azure Project
Once you've signed in, click the Windows Azure menu tab on the left side. When the Windows Azure page loads, you will see the project that you created during the registration process (see Step 1). See Figure 10, which will correspond to this step.
Figure 10. Windows Azure project list
Click the project hyperlink NAS-DEV. In your case, you should click the name of the project that corresponds to the one you created in Step 1.
8.1.3. Creating Windows Azure NotepadService
When the page loads, if you previously created services, you will see the list of the services, as shown in Figure 11. Let's create a new service that will host your WCF service by clicking the "+ New Service" link on the left side of the page.
Figure 11. Adding a new Azure service to the project
When the next page loads, you will be given an option to choose either "Storage Account" or "Hosted Services." Choose "Hosted Services." See Figure 12 for the options you will see displayed.
Figure 12. Choosing Hosted Services
When the Service Properties dialogue shown in Figure 13 displays, enter "NotepadService" as the Service Label and "This is the WCF service for the Windows Phone 7 Notepad demo application," as the Service Description. Now click the Next button to display the Hosted Service Dialogue on the page.
Figure 13. Creating Azure service
8.1.4. Configuring Windows Azure NotepadService
Now you're ready to configure the service that you created in the previous section.
When the Hosted Service dialogue displays, enter "NotepadService" as the Public Service Name of the Public Hosted Service URL name. Click the Check Availability button to make sure the service name is not taken by someone else.
In the Hosted Service Affinity Group section of the Hosted Service dialogue, you have two options to choose from. Typically, relating the affinity among other services allows you to run the services in the same region in order to optimize performance.
If you are creating multiple services that will interact with other services in the same region, then you will want to choose "Yes" and choose the existing Affinity Group from the drop-down.
If you create a new Affinity, you can associate to this affinity when you are creating other services. Choose "No" as you will not be creating multiple services that will require the services to be in the same region, and then select the "Anywhere in US" option from the drop-down.
See Figure 14 for appropriately filled information. Notice here that for the region you would want to choose the region that you are close to for optimal performance. If you are planning to deploy the application targeting a specific region, then you would want to make sure to choose the appropriate region here.
Figure 14. Configuring the Azure service
Click the Create button and you will see Figure 15. Now you are ready to deploy the WCF application that you created in the foregoing section. Notice here that you will be able to deploy first to staging to test your WCF and then deploy to production. This is a very nice feature in that you will be able to test the application running against a real cloud-based service without first deploying to production.
Figure 15. NotepadService main screen
Keep this browser open as you will be coming back and deploying the packages.
8.2. Deploying NotepadService to Windows Azure
In the foregoing steps, you prepared the NotepadService host, and now it is time for you to deploy NotepadService so that you can consume the Azure service from the phone. We will be deploying the service to staging first. Staging is where you test your service before going to production. This is a very convenient way of making sure your service works before deciding to go live.
8.2.1. Compiling and Publishing NotepadService
We will need a compiled binary so we can deploy to the Windows Azure host.
Go to your NotepadService project, stop the project if it is running, right-click the NotepadService project, and choose Publish.
The Publish Cloud Service window will appear. Choose Create Service Package Only, as shown in Figure 16.
Figure 16. Create a NotepadService package for Windows Azure
Click the OK button and you will notice that Windows Explorer will open with a directory where you will see two files: NotepadService.cspkg is the compiled binary of NotepadService and ServiceConfiguration.cscfg is the configuration file used by Windows Azure. Take note of the directory path as you will be uploading these files to Windows Azure.
8.2.2. Deploying NotepadService.cspkg and ServiceConfiguration.cscfg to Windows Azure
You will be deploying the packages created in the previous steps to Windows Azure.
Go to your browser where the NotepadService host main screen is, as shown in Figure 17.
Click the "Staging Deploy..." button.
In the Application Package section, click the Browse button and select NotepadService.cspkg. In Configuration Settings, click Browse to select ServiceConfiguration.cscfg, and choose Automatic for Select OS Upgrades. It is best to have Azure upgrade the OS automatically because each upgrade will include security patches and framework updates. In "Choose a label for this deployment," put "Version 1.0.0". It is best to label the service you are deploying using the version scheme to overcome any future confusion of what is deployed to the Azure service. You should see a screen that resembles Figure 17.
Figure 17. Staging Deployment screen
Click Deploy. The main screen page will be loaded, as shown in Figure 18.
Figure 18. NotepadService main screen after packages are uploaded
Click Run to run NotepadService. This step will take a while, as long as five minutes. When the service is ready, you will see the Ready status. Notice here that there is a temporary web site URL, which now you can use in your Notepad phone application.
9. Testing the Notepad Application Against NotepadService Azure Service
In the foregoing steps, you deployed NotepadService to the Windows Azure host. You will be changing the Notepad phone configuration to point to the web service that is hosted in Windows Azure and test in the same way you tested against when the service was deployed locally to your machine.
Go to Visual Studio with the Notepad project.
In Solution Explorer under the Notepad project, open ServiceReferences.ClientConfig. Change the endpoint address from 127.0.0.1:81 to the URL that you received when you deployed to staging in previous steps. See Figure 19 with the changed endpoint address.
Figure 19. Changing the service endpoint to the Windows Azure address
Make sure that NotepadService is in Ready status, and then press F5 to run your Notepad phone application in the emulator. Follow the previous steps to test the Notepad application—it should exhibit exactly the same behavior, except that now you are running your Notepad application against the Windows Azure service.