Exercise 7: Testing the Application in the Cloud

In this exercise, you will publish the PartsServiceEnhanced Windows Azure WCF Service to Windows Azure, configure the Windows Phone 7 application to access the service, and test the Windows Phone 7 application.

Task 1 – Packaging the WCF Service for Publishing to Windows Azure

In this task, you will package the PartsServiceEnhanced WCF Service for Azure publishing.

  1. Return to the WP7.Cloud.PartServiceEnhanced Microsoft Visual Studio 2010 solution.
  2. Press Shift-F5 to stop the debugger.
  3. In the Solution Explorer, right click the WCFServiceWebRoleEnhanced project and select Clean.
  4. In the Solution Explorer, right click the WCFServiceWebRoleEnhanced project and select Build
  5. In the Solution Explorer, right click the WP7.Cloud.PartsServiceEnhanced project and select Clean.
  6. In the Solution Explorer, right click the WP7.Cloud.PartsServiceEnhanced project and select Build
  7. In the Solution Explorer, right click the WP7.Cloud.PartsServiceEnhanced solution and select Clean Solution.
  8. In the Solution Explorer, right click the WP7.Cloud.PartsServiceEnhanced solution and select Build Solution.
  9. In the Solution Explorer, right click the WP7.Cloud.PartsServiceEnhanced project and select Publish.
  10. There are two ways to publish the service to Windows Azure.
    1. Create a service package, uploading it to Windows Azure.
    2. Directly deploying to Windows Azure.

      In this scenario, create the service package and upload it to Windows Azure.

  11. Select the Create Service Package Only radio button in the Publish dialog box, and select OK.

    Figure 22

    Deploy Windows Azure project dialog

  12. The service package is created in a folder named Publish inside the bin directory. You can access it from the following location:%TrainingKitPath%\Labs\IntegratingAzureCloudServicesandData\Source\Before\WP7.Cloud.PartsServiceEnhanced \bin\Debug\PublishTwo files are created at the above location. – The service package file (.cspkg) and the service configuration file (.cscfg)

Task 2 – Uploading the Deployment Package and Configure the PartsServiceEnhanced in Windows Azure

In this task, you will upload the deployment package and configure the PartsServiceEnhanced WCF Service in Windows Azure.

  1. Open Internet Explorer, and go to https://windows.azure.com.
  2. Login using your Windows Azure credentials. If you do not have a Windows Azure Account, sign-up for a new one.
  3. Create a new Hosted service by clicking the New Hosted Service from the ribbon menu.

    Figure 23

    New Hosted Service

  4. Configure the new service as follows:
    1. Choose a subscription: Select the name of Azure subscription. (You would have provided this information while signing up for the Azure account.)
    2. Name of the Service: Provide a user friendly name to the service.
    3. URL prefix of your service: This is a unique URL. Choose an available URL.

      Note:
      Error: Note format was corrupted. Title should be bold.

    4. Region or Affinity group: This is the physical location of the Azure datacenter hosting your service. Choose a region.
    5. Deployment Options: Select “Deploy to production environment”.

      In this scenario, the service is published directly to a production environment, but as a best practice, publish the service to a staging environment, and test it on staging before publishing it to Production.

    6. Deployment Name: A user-friendly name to identify the service.
    7. Package Location: Select “Browse Locally”, browse to the .cspkg file that you published earlier, and select the file.
    8. Configuration file: Select “Browse Locally”, browse to the .cscfg file that you published earlier, and select the file.
    9. Click OK.

      Figure 24

      New Hosted Service dialog

  5. If you see a warning, click Yes to override and submit.

    This warning indicates that this deployment is a single instance deployment. For a 99.95% uptime Microsoft recommends at least 2 instances. You can always increase the number of instances in the Production deployment by changing it in the configuration file.

    Figure 25

    Deployment warning

  6. It could take a few minutes for the production environment to be ready. The image below shows a production environment when ready.

    Figure 26

    Deployment status

    Note:
    The DNS name in the right panel is the production URL.

  7. Open Internet Explorer.
  8. In the web browser, navigate to the PartService.svc file to test the deployment.

    Example: https://partsserviceenhanced.cloudapp.net/partservice.svc

    Note:
    The URL will be different in your environment. The URL follows the convention https://<DNS name>.cloudapp.net/partservice.svc.

    Figure 27

    PartsService page

Task 3 – Configuring the Windows Phone 7 Application to Access the Service Deployed to Windows Azure

In this task, you will modify the ServiceReferences.ClientConfig file in the Windows Phone application to set the endpoint for the PartsServiceEnhanced Windows Azure WCF Service to the production deployment you created in the previous task.

  1. In the WP7.Cloud.PartsClient project, in the ViewModels folder, open the ServiceReferences.ClientConfig file.
  2. Locate the BasicHttpBinding_IPartService endpoint element.
  3. Modify the address attribute in the BasicHttpBinding_IPartService endpoint element. Replace the existing address value with the URL to the PartsService WCF Service in Windows Azure.

    XML

    <endpoint address=" https://<DNS name>.cloudapp.net/partservice.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IPartService" contract="PartsService.IPartService" name="BasicHttpBinding_IPartService" />

    The following screenshot shows what the BasicHttpBinding_IPartService endpoint element looks like after the above code is modified.

    Note:
    Error: Note format was corrupted. Title should be bold.

    Figure 28

    Change the endpoint address

  4. Save ServiceReferences.ClientConfig.

Task 4 – Testing the Application with the PartsInventoryEnhanced SQL Azure Database

In this task, you will test the Windows Phone 7 application with the PartsInventoryEnhanced SQL Azure database deployed to the cloud.

  1. In the WP7.Cloud.PartsClient solution, select Windows Phone 7 Emulator in the deployment location dropdown list.
  2. In the WP7.Clioud.PartsClient solution, press F5.
  3. The Windows Phone 7 application starts in the emulator and displays the items from the Maintenance Requests SharePoint list.

    Figure 29

    Maintenance Requests from Azure

  4. Click the Fix the leaking boiler maintenance request in the list to select it.

    The Windows Phone 7 application displays the details for the selected maintenance request from the SharePoint list, as well as the replacements part stock levels for the company warehouses from the PartsInventoryEnhanced SQL Azure database.

    Notice the inventory level for the Denver warehouse is 0 and the Order pending status is No. In this scenario, the user contacts the vendor for the part and places an order to restock the Denver warehouse. After the user places the order, they update the database to indicate the order was placed.

    Figure 30

    Maintenance Request details

  5. Click the Part Ordered button next to the Denver warehouse.

    The Windows Phone 7 application calls the PartsServiceEnhanced Windows Azure WCF Service deployed to the cloud, which in turn updates the database to indicate an order was made to restock the Denver warehouse. Then, the Order Pending Status in the Windows Phone 7 application is updated.

    Figure 31

    Order pending status

  6. Return to Microsoft SQL Server 2008 R2 RTM - Management Studio Express.
  7. In the Object Explorer pane, expand the Databases folder and highlight the PartsInventoryEnhanced database. If you cannot see the PartsInventoryEnhanced database, highlight the Databases folder and click the refresh button in the Object Explorer toolbar.
  8. With the PartsInventoryEnhanced database highlighted, click the New Query button in the toolbar.
  9. Paste the following SQL commands into the query window. These commands query the Parts table.

    TSQL

    SELECT * FROM [Parts] GO

  10. Click Execute on the toolbar. Notice the OrderPending column for the corresponding inventory item in the Denver warehouse is updated.

    Figure 32

    Order status in SQL Azure