integrating sharepoint and cloud data in windows …az12722.vo.msecnd.net/.../lab.docx · web...

30
Hands-On Lab Integrating SharePoint and Cloud Data in Windows Phone 7 Applications Lab version: 1.0.0 Last updated: 4/13/2022 Page | 1

Upload: others

Post on 12-Mar-2020

2 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Integrating SharePoint and Cloud Data in Windows …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications that that use SQL Azure Data in addition to SharePoint

Hands-On LabIntegrating SharePoint and Cloud Data in Windows Phone 7 Applications

Lab version: 1.0.0

Last updated: 5/18/2023

Page | 1

Page 2: Integrating SharePoint and Cloud Data in Windows …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications that that use SQL Azure Data in addition to SharePoint

CONTENTS

OVERVIEW................................................................................................................................................. 3

EXERCISE 1: CREATING A SHAREPOINT LIST DATA SOURCE...........................................................5Task 1 – Deploying the List Template to a SharePoint Site..................................................................5

Task 2 – Creating the Maintenance Requests List................................................................................6

EXERCISE 2: CREATING A SQL AZURE DATABASE............................................................................8Task 1 – Creating a SQL Azure Storage Account..................................................................................8

Task 2 – Creating a SQL Azure Database Server...................................................................................8

Task 3 – Creating a SQL Azure Database............................................................................................11

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

EXERCISE 4: CREATING THE WINDOWS PHONE 7 APPLICATION...................................................15Task 1 – Beginning the Exercise.........................................................................................................15

Task 2 – Configuring Constants in the Windows Phone 7 Application...............................................16

Task 3 – Generating the SQL Azure OData Proxy Class......................................................................16

Task 4 – Retrieving Maintenance Requests from SharePoint............................................................18

Task 5 – Retrieving Replacement Part Inventory Levels from SQL Azure...........................................19

EXERCISE 5: TESTING IN THE CLOUD.................................................................................................21Task 1 – Testing the Application with the PartsInventory SQL Azure Database.................................21

SUMMARY................................................................................................................................................ 24

Page | 2

Page 3: Integrating SharePoint and Cloud Data in Windows …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications that that use SQL Azure Data in addition to SharePoint

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 query the SQL Azure database with the OData Client Library for Windows Phone 7 Series CTP 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

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 ToolsPage | 3

Page 4: Integrating SharePoint and Cloud Data in Windows …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications that that use SQL Azure Data in addition to SharePoint

◦ 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 1Required downloads

KB981002- WCF: Hotfix rollup in .NET 3.5 SP1 for Win 7 and Win 2k8 R2

◦ http://code.msdn.microsoft.com/KB981002

Page | 4

Page 5: Integrating SharePoint and Cloud Data in Windows …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications that that use SQL Azure Data in addition to SharePoint

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.

3. Click Site Actions, and select Site Settings.

4. In the Galleries section, click List templates.

5. In the Ribbon, click the Documents tab.

Page | 5

Page 6: Integrating SharePoint and Cloud Data in Windows …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications that that use SQL Azure Data in addition to SharePoint

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.

12. Verify the Maintenance Requests list template appears in the List Templates Gallery.

Figure 2Maintenance 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://fbawp7

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.

5. Select the Maintenance Requests list.

Page | 6

Page 7: Integrating SharePoint and Cloud Data in Windows …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications that that use SQL Azure Data in addition to SharePoint

Figure 3Create 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 4The new Maintenance Requests list

Page | 7

Page 8: Integrating SharePoint and Cloud Data in Windows …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications that that use SQL Azure Data in addition to SharePoint

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 5New SQL Azure 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

Note: The dialog will verify the selected url is not already in use. If it is in use you must select a new url.

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

Page | 8

Page 9: Integrating SharePoint and Cloud Data in Windows …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications that that use SQL Azure Data in addition to SharePoint

In this task, you will create a SQL Azure database server.

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.

3. In the left pane, click Database.

Figure 6Choose Database

4. In the left pane select a subscription.

5. In the main menu, in the Server section, click Create.

Figure 7Create 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.

Page | 9

Page 10: Integrating SharePoint and Cloud Data in Windows …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications that that use SQL Azure Data in addition to SharePoint

13. In the IP range start textbox, enter 0.0.0.0.

14. In the IP range end textbox, enter 255.255.255.0.

15. Click OK.

Figure 8Create Server dialog

16. Click Finish.

Page | 10

Page 11: Integrating SharePoint and Cloud Data in Windows …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications that that use SQL Azure Data in addition to SharePoint

Figure 9Server Information page

17. Notice the Fully Qualified DNS Name. The fully qualified domain name is used to connect to the SQL Azure database. The name is unique for each SQL Azure database created.

18. Do not close the web browser. Leave it open so you can come back to it later in the lab and retrieve the Fully Qualified DNS Name for your 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.

Page | 11

Page 12: Integrating SharePoint and Cloud Data in Windows …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications that that use SQL Azure Data in addition to SharePoint

8. Paste the following command into the query window:

TSQL

CREATE DATABASE PartsInventory (MAXSIZE=1GB)

9. Click Execute on the toolbar.

10. In the Object Explorer pane, expand the Databases folder and highlight the PartsInventory database. If you cannot see the PartsInventory, highlight the Databases folder and click the refresh button in the Object Explorer toolbar.

11. With the PartsInventory 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 [PartsInventory]GO

SET ANSI_NULLS ONGO

SET QUOTED_IDENTIFIER ONGO

SET ANSI_PADDING ONGO

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, CONSTRAINT [PK_ Parts] PRIMARY KEY CLUSTERED ( [ID] ASC)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF))

GO

SET ANSI_PADDING OFFGO

13. Click Execute on the toolbar.Page | 12

Page 13: Integrating SharePoint and Cloud Data in Windows …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications that that use SQL Azure Data in addition to SharePoint

14. With the PartsInventory 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 [PartsInventory].[dbo].[Parts]VALUES ('Denver', 'Fabrikam', 'BLR15000-S', 12)GOINSERT INTO [PartsInventory].[dbo].[Parts]VALUES ('Cincinnati', 'Litware', 'MP-4200', 2)GOINSERT INTO [PartsInventory].[dbo].[Parts]VALUES ('Springfield', 'Fabrikam', 'BLR15000-S', 11)GOINSERT INTO [PartsInventory].[dbo].[Parts]VALUES ('San Diego', 'Fabrikam', 'SD-1', 1)GOINSERT INTO [PartsInventory].[dbo].[Parts]VALUES ('Breckenridge', 'Fabrikam', 'SD-1', 3)GOINSERT INTO [PartsInventory].[dbo].[Parts]VALUES ('Denver', 'Litware', 'MP-4200', 6)GOINSERT INTO [PartsInventory].[dbo].[Parts]VALUES ('Philadelphia', 'Litware', 'MP-4200', 3)GO

16. Click Execute on the toolbar.

17. With the PartsInventory highlighted, click the New Query button in the toolbar.

18. Paste the following SQL command into the query window. This command will return the sample data inserted in the Parts table to verify the data exists.

TSQL

SELECT * FROM [PartsInventory].[dbo].[Parts]GO

19. Click Execute on the toolbar.

20. Verify the sample data exists in the Parts table.

Page | 13

Page 14: Integrating SharePoint and Cloud Data in Windows …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications that that use SQL Azure Data in addition to SharePoint

Figure 10The Parts table

21. Close Microsoft SQL Server 2008 R2 RTM - Management Studio Express.

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

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.

Page | 14

Page 15: Integrating SharePoint and Cloud Data in Windows …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications that that use SQL Azure Data in addition to SharePoint

Figure 11Configure OData Service Connection

6. Click Connect.

7. In the Database Information section, in the Database dropdown list, select PartsInventory.

8. Check the Enable OData checkbox.

9. In the User Mapping section, in the Anonymous User Access dropdown list, select dbo.

Figure 12User Mapping for the OData Service

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

Page | 15

Page 16: Integrating SharePoint and Cloud Data in Windows …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications that that use SQL Azure Data in addition to SharePoint

Exercise 4: Creating the Windows Phone 7 Application

In this exercise, you will create a Windows Phone 7 application to query the maintenance requests SharePoint list and the SQL Azure database created in exercise 2.

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.

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\IntegratingAzureCloudData\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 server name will be different.

Page | 16

Page 17: Integrating SharePoint and Cloud Data in Windows …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications that that use SQL Azure Data in addition to SharePoint

C#

public const string SQL_AZURE_DATABASE_URL = "https://odata.sqlazurelabs.com/OData.svc/v0.1/mysqlazuredb/PartsInventory";

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.

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>/PartsInventory /out:c:\PartsInventory.cs /Version:2.0 /DataServiceCollection

Figure 13Generate the proxy class

4. Copy the c:\PatrsInventory.cs file to the %TrainingKitPath%\Labs\Azure\Data\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\IntegratingAzureCloudData\Source\Before\WP7.Cloud.PartsClient\OData directory.

7. Select the PartsInventory.cs file.

8. Open the PartsInventory.cs file.

Page | 17

Page 18: Integrating SharePoint and Cloud Data in Windows …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications that that use SQL Azure Data in addition to SharePoint

9. Change the namespace to WP7.Cloud.PartsClient.

Figure 14Change the namespace

10. Save PartsInventory.cs.

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.2.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.

Page | 18

Page 19: Integrating SharePoint and Cloud Data in Windows …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications that that use SQL Azure Data in addition to SharePoint

3. Add the following code under the //TODO: 8.2.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 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 – Retrieving Replacement Part Inventory Levels from SQL Azure

In this task, you will retrieve the replacement part inventory levels from the PartsInventory SQL Azure database.

Page | 19

Page 20: Integrating SharePoint and Cloud Data in Windows …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications that that use SQL Azure Data in addition to SharePoint

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.2.3 comment to define the CheckInternalInventory method:

C#

public void CheckInternalInventory(string make, string model){ context = new PartsInventory(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 PartsInventory SQL Azure database to return the replacement part inventory levels from the PartsInventory 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.2.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();

foreach (Part part in results) { Parts.Add(part); }

Page | 20

Page 21: Integrating SharePoint and Cloud Data in Windows …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications that that use SQL Azure Data in addition to SharePoint

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

The CheckInternalInventoryCallback method fires when the call to the OData query to the PartsInventory 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 PartsInventory SQL Azure database.

4. Save MaintenanceTaskViewModel.cs.

Exercise 5: Testing in the Cloud

In this exercise, you will test the Windows Phone 7 application.

Task 1 – Testing the Application with the PartsInventory SQL Azure Database

In this task, you will test the Windows Phone 7 application with the PartsInventory 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 | 21

Page 22: Integrating SharePoint and Cloud Data in Windows …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications that that use SQL Azure Data in addition to SharePoint

Figure 15Maintenance Requests in the application

4. Click on one of the maintenance requests in the list to select it.Page | 22

Page 23: Integrating SharePoint and Cloud Data in Windows …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications that that use SQL Azure Data in addition to SharePoint

5. 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 PartsInventory SQL Azure database.

Figure 16

Page | 23

Page 24: Integrating SharePoint and Cloud Data in Windows …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications that that use SQL Azure Data in addition to SharePoint

Maintenance Request details

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. Finally, 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.

Page | 24