Documents
Resources
Learning Center
Upload
Plans & pricing Sign in
Sign Out

Lab

VIEWS: 17 PAGES: 47

									Hands-On Lab
Integrating SharePoint with Cloud Services
and Data in Windows Phone 7 Applications

Lab version:    1.0.0
Last updated:   12/4/2011




                                         Page | 1
CONTENTS

OVERVIEW ................................................................................................................................................... 4

EXERCISE 1: CREATING A SHAREPOINT LIST DATA SOURCE ........................................................... 6
       Task 1 – Deploying the List Template to a SharePoint Site ................................................................... 6
       Task 2 – Creating the Maintenance Requests List ................................................................................ 7

EXERCISE 2: CREATING A SQL AZURE DATABASE ............................................................................. 9
       Task 1 – Creating a SQL Azure Storage Account ................................................................................... 9
       Task 2 – Creating a SQL Azure Database Server ................................................................................... 9
       Task 3 – Creating a SQL Azure Database ............................................................................................. 12

EXERCISE 3: ENABLING ODATA ACCESS TO A SQL AZURE DATABASE ....................................... 14
       Task 1 – Enabling OData Access .......................................................................................................... 14

EXERCISE 4: CREATING A WCF SERVICE IN WINDOWS AZURE ....................................................... 16
       Task 1 – Beginning the Exercise .......................................................................................................... 16
       Task 2 – Implementing and Configuring the WCF Service .................................................................. 17

EXERCISE 5: CREATING THE WINDOWS PHONE 7 APPLICATION .................................................... 19
       Task 1 – Beginning the Exercise .......................................................................................................... 19
       Task 2 – Configuring Constants in the Windows Phone 7 Application ............................................... 20
       Task 3 – Generating the SQL Azure OData Proxy Class ....................................................................... 20
       Task 4 – Retrieving Maintenance Requests from SharePoint ............................................................. 22
       Task 5 – Adding a Reference to the Windows Azure WCF Service ..................................................... 23
       Task 6– Retrieving Replacement Part Inventory Levels from SQL Azure ............................................ 24
       Task 7 – Updating Replacement Part Order Status in SQL Azure ....................................................... 25
       Task 8 – Modifying the web.config File to Support the Cookie Container Used with Forms
       BasedAuthentication........................................................................................................................... 26

EXERCISE 6: TESTING THE APPLICATION WITH THE LOCAL WINDOWS AZURE WCF SERVICE 28
       Task 1 – Testing the Application with the PartsInventoryEnhanced SQL Azure Database ................. 28

EXERCISE 7: TESTING THE APPLICATION IN THE CLOUD ................................................................. 33
       Task 1 – Packaging the WCF Service for Publishing to Windows Azure ............................................. 34
       Task 2 – Uploading the Deployment Package and Configure the PartsServiceEnhanced in Windows
       Azure ................................................................................................................................................... 35


                                                                                                                                                      Page | 2
       Task 3 – Configuring the Windows Phone 7 Application to Access the Service Deployed to Windows
       Azure ................................................................................................................................................... 40
       Task 4 – Testing the Application with the PartsInventoryEnhanced SQL Azure Database ................. 41

SUMMARY .................................................................................................................................................. 46




                                                                                                                                                      Page | 3
Overview
Windows Phone 7 applications that that use SQL Azure Data in addition to SharePoint data enable
integration between SharePoint data and services with external data hosted in the cloud. Visual Studio
2010 provides a rich development environment for creating, deploying, and integrating Windows Azure
Service with Windows Phone 7 applications.


Objectives
In this hands-on lab, you will learn how to integrate SharePoint data with a SQL Azure Data in a
Windows Phone 7 application. You will learn how to create a SQL Azure database and enable OData
accesss to it. You will also learn how to query the SQL Azure database with the OData Client Library for
Windows Phone 7 Series CTP from a Windows Phone 7 application. Finally, you will learn how to use
SharePoint data to supplement the functionality in the Windows Phone 7 application.
          Learn how to integrate SharePoint data with a Windows Azure Service in a Windows Phone 7
           application.
          See how to create a SQL Azure database database and enable OData accesss to it.
          See how to create and deploy a Windows Azure Service.
          See how to query the SQL Azure database with the OData Client Library for Windows Phone
           7 Series CTP from a Windows Phone 7 application.

          See how to call the Windows Azure Service from a Windows Phone 7 application.
          Learn how to use SharePoint data to supplement the functionality in the Windows Phone 7
           application.



Prerequisites
The following is required to complete this hands-on lab:

 Note: See Setting Up A SharePoint and Windows Phone 7 Development Environment Module for
 instructions that describe how to set up the SharePoint and Windows Phone 7 developer machine.



          Windows 7 x64 installed with all Windows Updates installed, in one of the following
           scenarios.
               ◦   Installed on a physical machine
               ◦   Installed on a bootable VHD
                                                                                                 Page | 4
         SharePoint 2010 installed on the Windows 7 x64 developer machine configured with a site
         collection that uses Forms Based Authentication (FBA).
        Windows Phone 7 Developer Tools

          ◦   http://download.microsoft.com/download/1/7/7/177D6AF8-17FA-40E7-AB53-
              00B7CED31729/vm_web.exe

        Windows Phone 7 Developer Tools - January 2011 Update

          ◦   http://download.microsoft.com/download/6/D/6/6D66958D-891B-4C0E-BC32-
              2DFC41917B11/WindowsPhoneDeveloperResources_en-US_Patch1.msp
        Windows Phone Developer Tools Fix

          ◦   http://download.microsoft.com/download/6/D/6/6D66958D-891B-4C0E-BC32-
              2DFC41917B11/VS10-KB2486994-x86.exe

Note: The following prerequisites are not included in the Setting Up A SharePoint and Windows Phone
7 Development Environment Module installation instructions. If you are using a development machine
built according to the Setting Up A SharePoint and Windows Phone 7 Development Environment
Module instructions you must install these components.



        OData Client Library for Windows Phone 7 Series CTP
          ◦   http://www.microsoft.com/downloads/en/details.aspx?FamilyID=b251b247-70ca-4887-
              bab6-dccdec192f8d&displaylang=en
        Windows Azure SDK and Windows Azure Tools for Microsoft Visual Studio (March 2011)
          ◦   http://www.microsoft.com/downloads/en/details.aspx?FamilyID=7a1089b6-4050-4307-
              86c4-9dadaa5ed018
                  Download and install the files indicated in the screenshot below.




              Figure 1
              Required Downloads

                                                                                           Page | 5
          KB981002- WCF: Hotfix rollup in .NET 3.5 SP1 for Win 7 and Win 2k8 R2
            ◦   http://code.msdn.microsoft.com/KB981002

          Access to a Windows Azure account.
            ◦   Go to http://windows.azure.net to create an account.

          Microsoft SQL Server 2008 R2 RTM - Management Studio Express
            ◦   http://www.microsoft.com/downloads/en/details.aspx?FamilyID=56ad557c-03e6-4369-
                9c1d-e81b33d8026b&displaylang=en




Exercise 1: Creating a SharePoint List
Data Source
 Note: If you already performed the steps in the Integrating SharePoint and Cloud Services in Windows
 Phone 7 Applications lab from the Integrating SharePoint 2010 and Windows Azure Module you can
 skip this exercise.



In this exercise, you will deploy a list template to SharePoint and make a list based upon the template.
The list template defines a list used to hold maintenance requests. In this scenario, the Windows Phone
7 application will read the maintenance requests from the SharePoint list and query a SQL Azure
database to determine if the appropriate replacement parts associated with each maintenance request
are in stock. The Windows Phone 7 application will present this information to help maintenance
personnel complete maintenance requests.
In this exercise, you will enable OData access to the SQL Azure database.
Task 1 – Deploying the List Template to a SharePoint Site
In this task, you will deploy the maintenance requests list template to a SharePoint site. The list
template contains sample data used in the lab.
       1. Open Internet Explorer and navigate to the SharePoint Team Site configured for Forms
          Based Authentication.
           example: http://fbawp7
       2. Log into the site using site collection administrator credentials.
                                                                                                      Page | 6
       3. Click Site Actions, and select Site Settings.
       4. In the Galleries section, click List templates.
       5. In the Ribbon, click the Documents tab.
       6. Click Upload Document.
       7. Click Browse…
       8. Browse to the Maintenance Requests.stp file located at %TrainingKitPath%\
          Labs\IntegratingAzureCloudData\Source\Before and select it.
       9. Click Open.
       10. Click OK.
       11. Click Save. Verify the Maintenance Requests list template appears in the List Templates
           Gallery.




        Figure 2
        Maintenance Requests list template



Task 2 – Creating the Maintenance Requests List
In this task, you will use the maintenance requests list template to create the maintenance requests list.
       1. Open Internet Explorer and navigate to the SharePoint Team Site configured for Forms
          Based Authentication.
        example: http://wp7fba
       2. Log into the site using site collection administrator credentials.
       3. Click Site Actions and select More Options.
       4. In the Filter By section, select List.

                                                                                                  Page | 7
5. Select the Maintenance Requests list.




Figure 3
Create list dialog


6. In the Name textbox enter Maintenance Requests.
7. Click Create.
8. Verify the Maintenance Requests list contains the following sample data.




Figure 4
The new Maintenance Requests list with sample data




                                                                              Page | 8
Exercise 2: Creating a SQL Azure
Database
In this exercise, you will create a SQL Azure database. In this scenario, the Windows Phone 7 application
queries the SQL Azure database and passes in the product make and model. The SQL Azure database
stores the different warehouses that currently have the replacement parts in stock and how many
replacement parts are available in each warehouse.
Task 1 – Creating a SQL Azure Storage Account
In this task, you will open the lab solution in Visual Studio 2010.
       1. Open Internet Explorer, and go to http://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. Create a new Storage Account by clicking the New Storage Account
          from the ribbon menu.




        Figure 5
        New Azure Storage account


       3. In the Choose a subscription dropdown list, select the name of your Azure subscription. (You
          would have provided this information while signing up for the Azure account.)
       4. In the Enter a URL textbox, provide a URL for the storage account.
        Example: spwp7dev
       5. In the Choose a region or affinity group dropdown list, select a value close to you.
       6. Click Create.

Task 2 – Creating a SQL Azure Database Server
In this task, you will create a SQL Azure database server.
       1. Open Internet Explorer, and go to http://windows.azure.com.


                                                                                                 Page | 9
2. Login using your Windows Azure credentials. If you do not have a Windows Azure Account,
   sign-up for a new one.
3. In the left pane, click Database.




 Figure 6
 Select database


4. Select the appropriate subscription.
5. In the main menu, in the Server section, click Create.




 Figure 7
 Create new database


6. In the Create Server dialog, select a Region.
7. Click Next.
8. Enter an Administrator Login and password.
9. Click Next.
10. Check the Allow other Windows Azure services to access this server checkbox.
11. Click Add.
12. In the Rule name textbox enter Everything.
13. In the IP range start textbox, enter 0.0.0.0.
14. In the IP range end textbox, enter 255.255.255.0.
                                                                                   Page | 10
15. Click OK.




 Figure 8
 New server created


16. Click Finish.




 Figure 9

                      Page | 11
        Server details


       17. Notice the Fully Qualified DNS Name. This is used to connect to the SQL Azure database.

Task 3 – Creating a SQL Azure Database
In this task, you will create a SQL Azure database.
       1. Open Microsoft SQL Server 2008 R2 RTM - Management Studio Express.
       2. In the Connect to Server dialog, enter the Server name for your SQL Azure database server.

         Note: The Server name is the Fully Qualified DNS Name for the SQL Azure database server you
         created in task 2.



       3. In the Authentication dropdown list, select SQL Server Authentication.
       4. Enter the Login and Password for your SQL Azure account.
       5. Click Connect.
       6. In the Object Explorer pane, highlight the Databases folder.
       7. Click the New Query button on the toolbar.
       8. Paste the following command into the query window:
        TSQL
        CREATE DATABASE PartsInventoryEnhanced (MAXSIZE=1GB)



       9. Click Execute on the toolbar.
       10. 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.
       11. With the PartsInventoryEnhanced database highlighted, click the New Query button in the
           toolbar.
       12. Paste the following SQL commands into the query window. These commands create the
           Parts table.
        TSQL
        USE [PartsInventoryEnhanced]
        GO

        SET ANSI_NULLS ON

                                                                                             Page | 12
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[Parts](
   [ID] [int] IDENTITY(1,1) NOT NULL,
   [Warehouse] [varchar](256) NOT NULL,
   [Make] [varchar](256) NOT NULL,
   [Model] [varchar](256) NOT NULL,
   [NumberInStock] [varchar](256) NOT NULL,
   [OrderPending] [varchar](3),
  CONSTRAINT [PK_ Parts] PRIMARY KEY CLUSTERED
(
   [ID] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF)
)
GO

SET ANSI_PADDING OFF
GO



13. Click Execute on the toolbar.
14. With the PartsInventoryEnhanced database highlighted, click the New Query button in the
    toolbar.
15. Paste the following SQL commands into the query window. These commands create the
    sample data in the Parts table.
TSQL
INSERT   INTO [PartsInventoryEnhanced].[dbo].[Parts]
VALUES   ('Denver', 'Fabrikam', 'BLR15000-S', 0, 'No')
GO
INSERT   INTO [PartsInventoryEnhanced].[dbo].[Parts]
VALUES   ('Cincinnati', 'Litware', 'MP-4200', 2, 'No')
GO
INSERT   INTO [PartsInventoryEnhanced].[dbo].[Parts]
VALUES   ('Springfield', 'Fabrikam', 'BLR15000-S', 11, 'No')
GO
INSERT   INTO [PartsInventoryEnhanced].[dbo].[Parts]
VALUES   ('San Diego', 'Fabrikam', 'SD-1', 1, 'No')
GO
INSERT   INTO [PartsInventoryEnhanced].[dbo].[Parts]
VALUES   ('Breckenridge', 'Fabrikam', 'SD-1', 3, 'No')
                                                                                   Page | 13
        GO
        INSERT   INTO [PartsInventoryEnhanced].[dbo].[Parts]
        VALUES   ('Denver', 'Litware', 'MP-4200', 6, 'No')
        GO
        INSERT   INTO [PartsInventoryEnhanced].[dbo].[Parts]
        VALUES   ('Philadelphia', 'Litware', 'MP-4200', 3, 'No')
        GO



       16. Click Execute on the toolbar.
       17. With the PartsInventoryEnhanced highlighted, click the New Query button in the toolbar.
       18. Paste the following SQL commands into the query window. These commands create the
           sample data in the Parts table.
        TSQL
        SELECT * FROM [PartsInventoryEnhanced].[dbo].[Parts]
        GO



       19. Click Execute on the toolbar.
       20. Verify the sample data exists in the Parts table.




        Figure 10
        Sample data table




Exercise 3: Enabling OData Access to a
SQL Azure Database
In this exercise, you will enable OData access to the SQL Azure database.
Task 1 – Enabling OData Access
                                                                                           Page | 14
In this task, you will open the lab solution in Visual Studio 2010.
       1. Open Internet Explorer, and go to https://www.sqlazurelabs.com.
       2. In left menu, click SQL Azure OData Service.
       3. Login using your Windows Azure credentials.
       4. In the Connection Information section, in the Server Name textbox, enter the Fully Qualified
          DNS Name for the SQL Azure database server created in exercise 2.
       5. In the Connection Information section, enter your SQL Azure administrator password.




        Figure 11
        OData Connection information


       6. Click Connect.
       7. In the Database Information section, in the Database dropdown list, select
          PartsInventoryEnhanced.
       8. Check the Enable OData checkbox.
       9. In the User Mapping section, in the Anonymous User Access dropdown list, select dbo.




                                                                                             Page | 15
        Figure 12
        OData service connection address



          Note: The Windows Phone 7 application uses the URL displayed at the bottom of the web
          page to interact with the PartsInventoryEnhanced SQL Azure database.




Exercise 4: Creating a WCF Service in
Windows Azure
In this exercise, you will create a Windows Azure Service. In this scenario, the Windows Phone 7
application calls the Windows Azure Service and passes in the product make and model. The Windows
Azure Service returns the lead-time to order and receive the corresponding replacement part from a
parts vendor.
Task 1 – Beginning the Exercise
In this task, you will open the lab solution in Visual Studio 2010.

                                                                                          Page | 16
       1. Make sure that you have downloaded and installed the items listed in System Requirements
          above prior to beginning this exercise.
       2. Launch Visual Studio 2010 as administrator and open the lab project by selecting File » Open
          » Project.
                a. Browse to the WP7.Cloud.PartsServiceEnhanced.sln file located at
                   %TrainingKitPath%\ Labs\IntegratingAzureCloudServicesandData\Source\Before
                   and select it.
                b. Click Open to open the solution.

Task 2 – Implementing and Configuring the WCF Service
In this task, you will implement a service operation in the PartServiceEnhanced WCF service to return
the ordering lead-time for a given part.
       1. In the WCFServiceWebRoleEnhanced project, open the file PartService.svc.cs.
       2. Add the following code under the //TODO: 8.3.1 comment to define the UpdateOrderStatus
          method:
        C#
        public int UpdateOrderStatus(int ID, bool orderPending)
        {
           string orderPendingValue = string.Empty;

             if (orderPending)
             {
                orderPendingValue = "Yes";
             }
             else
             {
                orderPendingValue = "No";
             }

             using (TransactionScope scope = new TransactionScope())
             {
                using (SqlConnection conn = new SqlConnection(RoleEnvironment.
                   GetConfigurationSettingValue("DatabaseConnectionString")))
                {
                   string updateOrderPending = "UPDATE Parts " +
                      "SET OrderPending = '" + orderPendingValue + "'" +
                      "WHERE ID = " + ID.ToString();
                   SqlCommand cmd = new SqlCommand(updateOrderPending, conn);
                   cmd.CommandType = CommandType.Text;

                   conn.Open();
                   cmd.ExecuteNonQuery();

                                                                                               Page | 17
         }

         scope.Complete();
     }

     return 1;
 }



 The above code uses ADO.NET to connect to the PartsInventoryEnhanced database and update
 the OrderPending column for the corresponding replacement part and warehouse.
3. Open the ServiceConfiguration.cscfg file.
4. Modify the DatabaseConnectionString elements value attribute to match the SQL Azure
   database server you created in exercise 2.
     a. Change the Data Source, ID, and Password values.
         The following code snippet shows the DatabaseConnectionString modified to work with
         a SQL Azure database server named snvnv617ib. You database name will be different.
         XML
         <Setting name="DatabaseConnectionString" value="Data Source=[SQL Azure
         Database Name].database.windows.net;Initial
         Catalog=PartsInventoryEnhanced;User ID=admin;Password=pass@word1" />



             Note: The Server Name is the Fully Qualified DNS Name for the SQL Azure database
             server you created in task 2.



5. Save the ServiceConfiguration.cscfg file.
6. In the Solution Explorer, right click the PartService.svc file and select Set As Start Page.
7. Press the F5 key to run the Azure Web Role in the local Azure AppFabric simulation
   environment. This causes the web roles to run on your local machine.
8. Verify the PartService.svc service is available when it opens in Internet Explorer.
9. Do not stop the WP7.Cloud.PartsService project. You will use the running instance of the
   service in upcoming steps.




                                                                                           Page | 18
        Figure 13
        PartsService page




Exercise 5: Creating the Windows Phone
7 Application
In this exercise, you will create a Windows Phone 7 application to query the maintenance tasks
SharePoint list and the SQL Azure database created in exercise 2. You will also use the
PartsServiceEnhanced Windows Azure WCF Service to update data in the PartsInventoryEnhanced SQL
Azure database.
Task 1 – Beginning the Exercise
In this task, you will open the lab solution in Visual Studio 2010.
       1. Make sure that you have downloaded and installed the items listed in System Requirements
          above prior to beginning this exercise.


                                                                                         Page | 19
       2. Launch Visual Studio 2010 as administrator and open the lab project by selecting File » Open
          » Project.
                a. Browse to the WP7.Cloud.PartsClient.sln file located at %TrainingKitPath%\
                   Labs\IntegratingAzureCloudServicesandData\Source\Before and select it.
                b. Click Open to open the solution.

Task 2 – Configuring Constants in the Windows Phone 7 Application
In this task, you will configure the constants used in the Windows Phone 7 application to work with your
development environment.
       1. In the WP7.Cloud.PartsClient project, in the Utilities folder, open the Constants.cs file.
       2. Change the value for the USER_NAME and USER_PASSWORD constants to represent a
          Forms Based Authentication user specific to your development environment. For this lab,
          the user requires reader permissions.
       3. Change the value for the AUTHENTICATION_SERVICE_URL constant to the URL specific to
          your development environment.
             The following code example demonstrates the value for a SharePoint server named fbawp7.
        C#
        public const string AUTHENTICATION_SERVICE_URL =
        "http://fbawp7/_vti_bin/authentication.asmx";



       4. Change the value for the SQL_AZURE_DATABASE_URL constant to the URL specific to the
          SQL Azure database created in exercise 2.
             The following code example demonstrates the value for a SQL Azure database server named
             mysqlazuredb. Your database name will be different.
        C#
        public const string SQL_AZURE_DATABASE_URL =
        "https://odata.sqlazurelabs.com/OData.svc/v0.1/mysqlzauredb/PartsInventoryEnha
        nced";




Task 3 – Generating the SQL Azure OData Proxy Class
In this task, you will use the datasvcutil.exe command line program to generate a proxy class for the
PartsInventory SQL Azure database.
       1. Open a command prompt.
       2. Change to the %System%\Microsoft.NET\Framework\v4.0.30319 directory.

                                                                                                Page | 20
3. Execute the following command. Replace the <SQL Azure Database Server Name> token
   with the name of the SQL Azure database server created in exercise 2.
Command
Datasvcutil.exe /uri:https://odata.sqlazurelabs.com/OData.svc/v0.1/<SQL Azure
Database Server Name>/PartsInventoryEnhanced /out:c:\PartsInventoryEnhanced.cs
/Version:2.0 /DataServiceCollection




Figure 14
Create proxy for service


4. Copy the c:\PatrsInventoryEnhanced.cs file to the
   %TrainingKitPath%\Labs\Azure\ServicesAndData\Source\Before\WP7.Cloud.PartsClient\
   OData directory.
5. In the Solution Explorer, right click the OData folder, select Add, and then select Existing
   Item.
6. Browse to the %TrainingKitPath%\
   Labs\IntegratingAzureCloudServicesandData\Source\Before\WP7.Cloud.PartsClient\ODat
   a directory.
7. Select the PartsInventoryEnhanced.cs file.
8. Open the PartsInventoryEnhanced.cs file.
9. Change the namespace to WP7.Cloud.PartsClient.




Figure 15
Change the namespace


10. Save PartsInventoryEnhanced.cs.


                                                                                         Page | 21
Task 4 – Retrieving Maintenance Requests from SharePoint
In this task, you will use the SharePoint lists.asmx Web service to return maintenance requests from the
SharePoint list.
       1. In the WP7.Cloud.PartsClient project, in the ViewModels folder, open the
          MainViewModel.cs file.
       2. Add the following code under the //TODO: 8.3.1 comment to define the
          LoadMaintenanceTasks method:
        C#
        public void LoadMaintenanceTasks()
        {
           XElement viewFields = new XElement("ViewFields",
              new XElement("FieldRef",
                 new XAttribute("Name", "Title")),
                    new XElement("FieldRef",
                       new XAttribute("Name", "Body")),
                          new XElement("FieldRef",
                             new XAttribute("Name", "Make")),
                                new XElement("FieldRef",
                                   new XAttribute("Name", "Model")));

             WP7.Cloud.PartsClient.SPListsService.ListsSoapClient lists =
                new WP7.Cloud.PartsClient.SPListsService.ListsSoapClient();
             lists.CookieContainer = App.CookieJar;
             lists.GetListItemsCompleted +=
                new EventHandler<WP7.Cloud.PartsClient.SPListsService.
                   GetListItemsCompletedEventArgs>(lists_GetListItemsCompleted);
             lists.GetListItemsAsync(Constants.SHAREPOINT_LIST_NAME,
                string.Empty, null, viewFields, null, null, null);
        }



        The above code uses the proxy class Visual Studio 2010 generated for the lists.asmx service to
        query the Maintenance Tasks SharePoint list.
       3. Add the following code under the //TODO: 8.3.2 comment to define the
          lists_GetListItemsCompleted method:
        C#
        void lists_GetListItemsCompleted(object sender,
           WP7.Cloud.PartsClient.SPListsService.GetListItemsCompletedEventArgs e)
        {
           IEnumerable<XElement> rows =
              e.Result.Descendants(XName.Get("row", "#RowsetSchema"));
           IEnumerable<SPMaintenanceTask> maintenanceTasks =
              from element in rows

                                                                                               Page | 22
               select new SPMaintenanceTask
               {
                  Title = (string)element.Attribute("ows_Title"),
                  Body = Utils.HtmlToText((string)element.Attribute("ows_Body")),
                  Make = (string)element.Attribute("ows_Make"),
                  Model = (string)element.Attribute("ows_Model")
               };

           Deployment.Current.Dispatcher.BeginInvoke(() =>
           {
              if (MaintenanceTasks == null)
              {
                  MaintenanceTasks = new ObservableCollection<SPMaintenanceTask>();
              }
              MaintenanceTasks.Clear();
              maintenanceTasks.ToList().ForEach(a => MaintenanceTasks.Add(a));
              });
       }



       The lists_GetListItemsCompleted method fires when the call to the lists.asmx SharePoint Web
       service completes. The method parses the result set, creates an instance of the
       SPMaintenanceTask that represents each maintenance task in the SharePoint list, and adds the
       SPMaintenanceTask instances to the MaintenanceTasks observable collection. The
       MaintenanceTasks observable collection is bound to the MainPage user control in the Windows
       Phone 7 application. The MainPage user control displays the maintenance requests retrieved
       from the SharePoint list.
      4. Save MainViewModel.cs.



Task 5 – Adding a Reference to the Windows Azure WCF Service
In this task, you will add a reference to the PartsServiceEnhanced Windows Azure WCF Service created
in Exercise 2
       1. In the Solution Explorer, in the WP7.Parts.Client project, right click Service References and
          select Add Service Reference.
       2. In the Address textbox enter the URL to the local running instance of the
          PartsServiceEnhanced Windows Azure Service.
           Example: http://127.0.0.1:82/PartService.svc?wsdl
       3. Click Go.
       4. Once the service is resolved, enter PartsService in the Namespace textbox.
       5. Click OK.
                                                                                               Page | 23
Task 6– Retrieving Replacement Part Inventory Levels from SQL Azure
In this task, you will retrieve the replacement part inventory levels from the PartsInventoryEnhanced
SQL Azure database.
       1. In the WP7.Cloud.PartsClient project, in the ViewModels folder, open the
          MaintenanceTaskViewModel.cs file.
       2. Add the following code under the //TODO: 8.3.3 comment to define the
          CheckInternalInventory method:
        C#
        public void CheckInternalInventory(string make, string model)
        {
           context = new PartsInventoryEnhanced(new
        Uri(Constants.SQL_AZURE_DATABASE_URL));
           Uri requestUri = new Uri(context.BaseUri.OriginalString +
               "/Parts()?$filter=(Make eq '" + make + "') and (Model eq '" + model +
        "')");
           context.BeginExecute<Part>(requestUri, CheckInternalInventoryCallback,
        null);
        }



        The above code uses the proxy class Visual Studio 2010 generated for the
        PartsInventoryEnhanced SQL Azure database to return the replacement part inventory levels
        from the PartsInventoryEnhanced SQL Azure database. The OData query uses the $filter
        querystring parameter to return only the rows of data that match the make and model of the
        part associated with the selected maintenance request.
       3. Add the following code under the //TODO: 8.3.4 comment to define the
          CheckInternalInventoryCallback method:
        C#
        private void CheckInternalInventoryCallback(IAsyncResult asyncResult)
        {
           IEnumerable<Part> results;
           results = context.EndExecute<Part>(asyncResult).ToList() as
        IEnumerable<Part>;

             Deployment.Current.Dispatcher.BeginInvoke(() =>
             {
                if (Parts == null)
                {
                   Parts = new ObservableCollection<Part>();
                }

                Parts.Clear();
                                                                                               Page | 24
                  foreach (Part part in results)
                  {
                     Parts.Add(part);
                  }

                  PartCount = Parts.Count().ToString();
            });
       }



       The CheckInternalInventoryCallback method fires when the call to the OData query to the
       PartsInventoryEnhanced SQL Azure database completes. First, the method takes the result set,
       and creates an IEnumerable list of type Part. The Part class is defined in the OData proxy class.
       Then a new instance of the Parts observable collection is created and each Part returned from
       the result set is added to the observable collection. The Parts observable collection is bound to
       the MaintenanceTaskView user control in the Windows Phone 7 application. This collection is
       used to display the list of warehouses that currently stock the part and how many parts are
       available in each warehouse.
       Then, the CheckInternalInventoryCallback method sets the PartCount property equal to the
       number of items returned by the query. The PartCount property is bound to the
       MaintenanceTaskView user control in the Windows Phone 7 application. This property is used
       to display the number of warehouses that currently stock the part.
       The MaintenanceTaskView user control displays detailed information for a maintenance
       request selected in the MainPage user control. The detailed information includes the metadata
       about a give maintenance request from the SharePoint list, as well as the replacement part
       inventory level data from the PartsInventoryEnhanced SQL Azure database.
      4. Save MaintenanceTaskViewModel.cs.

Task 7 – Updating Replacement Part Order Status in SQL Azure
In this task, you will use the PartsServiceEnhanced Windows Azure WCF Service to update data in the
PartsInventoryEnhanced SQL Azure database.
       1. In the WP7.Cloud.PartsClient project, in the ViewModels folder, open the
          MaintenanceTaskViewModel.cs file.
       2. Add the following code under the //TODO: 8.3.5 comment to define the
          UpdateInventoryRecord method:
       C#
       public void UpdateInventoryRecord(int ID)
       {
          WP7.Cloud.PartsClient.PartsService.PartServiceClient partsService =

                                                                                               Page | 25
               new PartsService.PartServiceClient();
            partsService.UpdateOrderStatusAsync(ID, true);
            partsService.UpdateOrderStatusCompleted +=
               new EventHandler<PartsService.UpdateOrderStatusCompletedEventArgs>
               (partsService_UpdateOrderStatusCompleted);
       }



       The above code uses the proxy class Visual Studio 2010 generated for the
       PartsInventoryEnhanced Windows Azure WCF Service update data in the
       PartsInventoryEnhanced SQL Azure database.
       3. Add the following code under the //TODO: 8.3.6 comment to define the
          partsService_UpdateOrderStatusCompleted method:
       C#
       void partsService_UpdateOrderStatusCompleted(object sender,
          PartsService.UpdateOrderStatusCompletedEventArgs e)
       {
          CheckInternalInventory(this.dataModel.Make, this.dataModel.Model);
       }



       The partsService_UpdateOrderStatusCompleted method fires when the call to the update the
       PartsInventoryEnhanced SQL Azure database completes. It calls the CheckInternalInventory
       method to refresh the UI.
      4. Save MaintenanceTaskViewModel.cs.

Task 8 – Modifying the web.config File to Support the Cookie Container Used with Forms
BasedAuthentication
In this task, you will modify the web.config file to support the CookieContainer used with Forms
BasedAuthentication. The code used to authenticate to the SharePoint server in this lab uses Forms
Based Authentication. Forms Based Authentication requires the use of a CookieContainer. Please see
Module 6 for more information about Forms Based Authentication.
       1. In the WP7.Cloud.PartsClient project, in the ViewModels folder, open the
          ServiceReferences.ClientConfig file.
       2. Locate the ListsSoap binding element.
       3. Add the following attribute to the ListsSoap binding element.
       XML
       enableHttpCookieContainer="true"



                                                                                           Page | 26
The following screenshot shows what the ListSoap binding element looks like after the above
code is added.




Figure 16
Enable cookie support



 Note: The following exception will occur if you do not make this change to the
 ServiceReferences.ClientConfig file.




Figure 17
Invalid operation exception



 Note: If you change the interface to one or both of the services the application calls and need
 to update the service reference you will need to remove the XML code above from the
 ServiceReferences.ClientConfig file then update the service reference. After the service
 reference update is complete, add the XML code back to the ServiceReferences.ClientConfig
 file.




                                                                                       Page | 27
Exercise 6: Testing the Application with
the Local Windows Azure WCF Service
In this exercise, you will test the Windows Phone 7 application.
Task 1 – 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 and the PartsServiceEnhances Windows Azure WCF Service running in
the local AppFabric simulation environment.
       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.




                                                                                             Page | 28
Figure 18
Maintenance Requests in the application


4. Click the Fix the leaking boiler maintenance request in the list to select it.
                                                                                    Page | 29
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.




                                                                                      Page | 30
Figure 19
Maintenance Request details


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


                                                                 Page | 31
The Windows Phone 7 application calls the local PartsServiceEnhanced Windows Azure WCF
Service, 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 20
                                                                                   Page | 32
   Parts Order 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 21
   Parts order status updated




Exercise 7: Testing the Application in the
Cloud
                                                                                       Page | 33
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.
            a. Create a service package, uploading it to Windows Azure.
            b. 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.




                                                                                               Page | 34
       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.PartsServiceEnhance
       d \bin\Debug\Publish
       Two 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 http://windows.azure.com.
                                                                                              Page | 35
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:
    a. Choose a subscription: Select the name of Azure subscription. (You would have provided
       this information while signing up for the Azure account.)
    b. Name of the Service: Provide a user friendly name to the service.
    c. URL prefix of your service: This is a unique URL. Choose an available URL.

          Note: When you delete this service, the URL is immediately available to others.



    d. Region or Affinity group: This is the physical location of the Azure datacenter hosting
       your service. Choose a region.
    e. 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.
    f.   Deployment Name: A user-friendly name to identify the service.

                                                                                          Page | 36
g. Package Location: Select “Browse Locally”, browse to the .cspkg file that you published
   earlier, and select the file.
h. Configuration file: Select “Browse Locally”, browse to the .cscfg file that you published
   earlier, and select the file.
i.   Click OK.




     Figure 24
     New Hosted Service dialog


                                                                                    Page | 37
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.




                                                                                     Page | 38
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: http://partsserviceenhanced.cloudapp.net/partservice.svc

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




                                                                                        Page | 39
        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=" http://<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: The URL will be different in your environment.




        Figure 28
        Change the endpoint address


       4. Save ServiceReferences.ClientConfig.



                                                                                                Page | 40
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.




                                                                                             Page | 41
Figure 29
Maintenance Requests from Azure


4. Click the Fix the leaking boiler maintenance request in the list to select it.
                                                                                    Page | 42
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.




                                                                                      Page | 43
Figure 30
Maintenance Request details


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


                                                                 Page | 44
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
                                                                                  Page | 45
       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




Summary
In this hands-on lab, you saw how to integrate SharePoint data with SQL Azure data in a Windows Phone
7 application. You learned how to create a SQL Azure database database and enable OData accesss to it.

                                                                                            Page | 46
You learned how to how to create and deploy a Windows Azure Service. You learned how to query the
SQL Azure database with the OData Client Library for Windows Phone 7 Series CTP from a Windows
Phone 7 application. Finally, you learned how to call the Windows Azure Service from a Windows Phone
7 application.




                                                                                           Page | 47

								
To top