Creating Private Windows Phone 7 Applications That Use ...az12722.vo.msecnd.net/.../Lab.docx  ·...

41
Hands-On Lab Creating Private Windows Phone 7 Applications That Use Service Based Security Lab version: 1.0.0 Last updated: 5/3/2022 Page | 1

Transcript of Creating Private Windows Phone 7 Applications That Use ...az12722.vo.msecnd.net/.../Lab.docx  ·...

Page 1: Creating Private Windows Phone 7 Applications That Use ...az12722.vo.msecnd.net/.../Lab.docx  · Web viewCreating Private Windows Phone 7 Applications That Use Service Based Security

Hands-On LabCreating Private Windows Phone 7 Applications That Use Service Based Security

Lab version: 1.0.0

Last updated: 5/23/2023

Page | 1

Page 2: Creating Private Windows Phone 7 Applications That Use ...az12722.vo.msecnd.net/.../Lab.docx  · Web viewCreating Private Windows Phone 7 Applications That Use Service Based Security

CONTENTS

OVERVIEW................................................................................................................................................. 2First-Time Configuration of the Windows Azure Simulation Environment..........................................4

Using dsinit to Configure Development Storage..................................................................................5

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

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

EXERCISE 2: CREATING A WCF SERVICE IN WINDOWS AZURE........................................................8Task 1 – Beginning the Exercise...........................................................................................................8

Task 2 – Implementing and Configuring the WCF Service....................................................................8

EXERCISE 3: CREATING THE WINDOWS PHONE 7 APPLICATION...................................................11Task 1 – Beginning the Exercise.........................................................................................................11

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

Task 3 – Configuring the Reference to the SharePoint Lists.asmx Web Service.................................12

Task 4 – Adding a Reference to the Windows Azure WCF Service.....................................................13

Task 5 – Modifying the ServiceReferences.ClientConfig File to Support the Cookie Container Used with Forms Based Authentication......................................................................................................13

Task 6 – Implementing Code to Lock and Unlock the Application.....................................................14

Task 7 – Testing the Application in the Local Azure AppFabric Simulation Environment...................15

EXERCISE 4: DEPLOYING AND TESTING IN THE CLOUD...................................................................22Task 1 – Packaging the WCF Service for Publishing to Windows Azure.............................................22

Task 2 – Uploading the Deployment Package and Configuring the RegistrationService in Windows Azure.................................................................................................................................................23

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

Task 4 – Testing the Application with the RegistrationService Windows Azure WCF Service Deployed to the Cloud.......................................................................................................................................28

SUMMARY................................................................................................................................................ 34

OverviewPage | 2

Page 3: Creating Private Windows Phone 7 Applications That Use ...az12722.vo.msecnd.net/.../Lab.docx  · Web viewCreating Private Windows Phone 7 Applications That Use Service Based Security

The Windows Phone 7 marketplace does not have a concept of a private marketplace. Applications published to the marketplace are visible to everyone. When deploying an application for all the users in a large organization, using the marketplace is the most efficient way to go about it. Developers must take steps to ensure applications deployed to the public marketplace are only used by authorized employees and not the public. In this scenario, to ensure maximum security no usernames, passwords, or salts are stored on the Windows Phone device. These values must be entered each time the application is restarted.

Objectives

In this hands-on lab, you will learn how to create a Windows Phone 7 application that uses a Windows Azure WCF Service to unlock the application. You will also learn how to provide users the functionality they need to call the Windows Azure WCF Service and conditionally unlock the application based on the results returned from the service.

Learn how to create a Windows Azure WCF Service that validates the information necessary to unlock an application.

Learn how to provide users the functionality they need to call the Windows Azure WCF Service and conditionally unlock the 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 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

Page | 3

Page 4: Creating Private Windows Phone 7 Applications That Use ...az12722.vo.msecnd.net/.../Lab.docx  · Web viewCreating Private Windows Phone 7 Applications That Use Service Based Security

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

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 1Download Setup files

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.

First-Time Configuration of the Windows Azure Simulation Environment

Note: The Windows Azure SDK (included in Windows Azure Tools for Visual Studio) installs a simulation environment on your development machine for testing Azure applications locally before deploying

Page | 4

Page 5: Creating Private Windows Phone 7 Applications That Use ...az12722.vo.msecnd.net/.../Lab.docx  · Web viewCreating Private Windows Phone 7 Applications That Use Service Based Security

them to the cloud. The simulation environment consists of the development fabric to host web and worker roles, and the development storage which simulates cloud blob, table and queue storage locally.

Development storage uses SQL Server as its underlying storage mechanism, and by default the SDK will attempt to configure it to use SQL Server Express. If you do not have SQL Server Express installed before installing the SDK, or you wish to simply use an existing SQL Server instance to host the development storage database, you must run the dsinit command to select the SQL Server instance where the database will be created.

Please see instructions below for how to run dsinit.

Using dsinit to Configure Development Storage

1. Open a command prompt.

2. Edit the following command line as appropriate for your environment, where [AzureSDKInstallDrive] is the drive where you installed the Azure SDK (or Windows Azure Tools for Visual Studio), and [YourSqlInstance] is the SqlServer where you want to create the development storage database.

[AzureSDKInstallDrive]\ Program Files\Windows Azure SDK\v1.4\bin\devstore\dsinit.exe /sqlinstance:[YourSqlInstance]

Example Command Line:“C:\Program Files\Windows Azure SDK\v1.4\bin\devstore\dsinit.exe” /sqlinstance:.

3. Note that the sample command line above uses the value “.” for the sqlinstance argument, which specifies that the local default SQL instance will be used for development storage.

Exercise 1: Creating a SharePoint List Data Source

Note: This is the same list used in the Integrating SharePoint 2010 and Windows Azure module. If you have already installed it, you may 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, after the Windows Phone 7 application is unlocked, it will read the maintenance requests from

Page | 5

Page 6: Creating Private Windows Phone 7 Applications That Use ...az12722.vo.msecnd.net/.../Lab.docx  · Web viewCreating Private Windows Phone 7 Applications That Use Service Based Security

the SharePoint list. The Windows Phone 7 application will present this information to help maintenance personnel complete maintenance requests.

Task 1 – Deploying the List Template to a SharePoint Site

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

2. Open Internet Explorer and navigate to the SharePoint Team Site configured for Forms Based Authentication.

example: http://fbawp7

3. Log into the site using site collection administrator credentials.

4. Click Site Actions, and select Site Settings.

5. In the Galleries section, click List templates.

6. In the Ribbon, click the Documents tab.

7. Click Upload Document.

8. Click Browse…

9. Browse to the Maintenance Requests.stp file located at %TrainingKitPath%\ Labs\CreatingPrivateApplicationsUsingServices\Source\Before and select it.

10. Click Open.

11. Click OK.

12. Click Save.

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

Figure 2The Maintenance Requests list template

Page | 6

Page 7: Creating Private Windows Phone 7 Applications That Use ...az12722.vo.msecnd.net/.../Lab.docx  · Web viewCreating Private Windows Phone 7 Applications That Use Service Based Security

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.

Figure 3Create list dialog

Page | 7

Page 8: Creating Private Windows Phone 7 Applications That Use ...az12722.vo.msecnd.net/.../Lab.docx  · Web viewCreating Private Windows Phone 7 Applications That Use Service Based Security

6. In the Name textbox enter Maintenance Requests. Click Create.

7. Verify the Maintenance Requests list contains the following sample data.

Figure 4Maintenance Request list with data

Exercise 2: Creating a WCF Service in Windows Azure

In this exercise, you will create a Windows Azure WCF Service. In this scenario, the Windows Phone 7 application calls the Windows Azure WCF Service and passes in the application ID, application password, and registration key values entered by a user. The Windows Azure WCF Service uses these values to determine if they are valid to unlock the application and returns a message indicating success or failure. The Windows Phone 7 application uses the value returned from the Windows Azure WCF Service to conditionally unlock the application and enable its full functionality. When using this approach, use HTTPS to encrypt the communication channel between the Windows Phone 7 device and the Windows Azure WCF Service.

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.Private.Service.sln file located at %TrainingKitPath%\ Labs\CreatingPrivateApplicationsUsingServices\Source\Before\WP7.Private.Service and select it.

b. Click Open to open the solution.

Task 2 – Implementing and Configuring the WCF Service

Page | 8

Page 9: Creating Private Windows Phone 7 Applications That Use ...az12722.vo.msecnd.net/.../Lab.docx  · Web viewCreating Private Windows Phone 7 Applications That Use Service Based Security

In this task, you will implement a service operation in the RegistrationService WCF service to return the registration status for a Windows Phone 7 application.

1. In the RegisterWebRole project, open the file IRegistrationService. cs.

2. Add the following code under the //TODO: 9.2.1 comment to define the OperationContract for the Register method:

C#

[OperationContract]string Register(string applicationID, string applicationPassword, string applicationRegistrationKey);

The above code defines the OperationContract for the Register method and makes it available to call from another application.

3. In the RegisterWebRole project, open the file RegistrationService.svc.cs.

4. Add the following code under the //TODO: 9.2.2 comment to define the Register method:

C#

public string Register(string applicationID, string applicationPassword, string applicationRegistrationKey){ AesManaged aesManaged = null; MemoryStream memoryStream = null; CryptoStream cryptoStream = null;

try { Rfc2898DeriveBytes rfc2898DeriveBytes = new Rfc2898DeriveBytes(applicationPassword, Encoding.UTF8.GetBytes(applicationRegistrationKey), 99999);

aesManaged = new AesManaged(); aesManaged.IV = rfc2898DeriveBytes.GetBytes(16); aesManaged.Key = rfc2898DeriveBytes.GetBytes(32);

memoryStream = new MemoryStream(); cryptoStream = new CryptoStream(memoryStream, aesManaged.CreateEncryptor(), CryptoStreamMode.Write);

byte[] bytes = Encoding.UTF8.GetBytes(applicationID); cryptoStream.Write(bytes, 0, bytes.Length); cryptoStream.FlushFinalBlock();

Page | 9

Page 10: Creating Private Windows Phone 7 Applications That Use ...az12722.vo.msecnd.net/.../Lab.docx  · Web viewCreating Private Windows Phone 7 Applications That Use Service Based Security

if (ENCRYPTED_APP_KEY == Convert.ToBase64String(memoryStream.ToArray())) { return "Success"; } else { return "Failure"; } } finally { if (aesManaged != null) { aesManaged.Clear(); } if (memoryStream != null) { memoryStream.Close(); } if (cryptoStream != null) { cryptoStream.Close(); } }}

The Register method uses the cryptographic APIs to create an encrypted string. The cryptographic APIs use the applicationID, applicationPassword, and applicationRegistrationKey arguments to create the encrypted string. In this scenario, the Advanced Encryption Standard (AES) algorithm encrypts the string. AES uses a symmetric-key algorithm to encrypt data.

The following table describes how the arguments in the Register method are used by the cryptographic APIs use to create the encrypted string.

Register method parameter Cryptographic API

applicationID string to encrypt

applicationPassword Password

applicationRegistrationKey Salt

5. In the Solution Explorer, right click the RegistrationService.svc file and select Set As Start Page.

Page | 10

Page 11: Creating Private Windows Phone 7 Applications That Use ...az12722.vo.msecnd.net/.../Lab.docx  · Web viewCreating Private Windows Phone 7 Applications That Use Service Based Security

6. Press the F5 key to run the Azure Web Role in the local Azure AppFabric simulation environment. This causes the Azure Web Role to run on your local machine.

7. Verify the RegistrationService.svc service is available when it opens in Internet Explorer. You should be viewing the RegistrationService Service page.

8. Do not stop the WP7.Private.Service project. You will use the running instance of the service in upcoming steps.

Figure 5Registration Service page

Exercise 3: Creating the Windows Phone 7 Application

In this exercise, you will create a Windows Phone 7 application to query the maintenance tasks SharePoint list. You will also implement the code necessary to lock the application and the code to call the Windows Azure WCF Service to unlock the application.

Task 1 – Beginning the Exercise

Page | 11

Page 12: Creating Private Windows Phone 7 Applications That Use ...az12722.vo.msecnd.net/.../Lab.docx  · Web viewCreating Private Windows Phone 7 Applications That Use Service Based Security

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.Private.Service.PartsClient.sln file located at %TrainingKitPath%\ Labs\CreatingPrivateApplicationsUsingServices\Source\Before\WP7.Private.Service.PartsClient 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.Private.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";

Task 3 – Configuring the Reference to the SharePoint Lists.asmx Web Service

In this task, you will configure the reference to the SharePoint lists.asmx Web service.

1. In the Solution Explorer, double click the ServiceReferences.ClientConfig file to open it.

2. In the Endpoint element, change the address attribute to the URL for the lists.asmx SharePoint web service in the site where you created the Maintenance Tasks list.

Example: http://fbawp7/_vti_bin/lists.asmx

Figure6Page | 12

Page 13: Creating Private Windows Phone 7 Applications That Use ...az12722.vo.msecnd.net/.../Lab.docx  · Web viewCreating Private Windows Phone 7 Applications That Use Service Based Security

Configure the Lists service endpoint address

Task 4 – Adding a Reference to the Windows Azure WCF Service

In this task, you will add a reference to the RegistrationService Windows Azure WCF Service created in Exercise 2.

1. In the Solution Explorer, in the WP7.Private.Service.PartsClient 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 RegistrationService Windows Azure Service. This is the same URL you will see in the web browser in Exercise 2, step 8.

Example: http://127.0.0.1:84/RegistrationService.svc?wsdl

3. Click Go.

4. Once the service is resolved, enter RegistrationService in the Namespace textbox.

5. Click OK.

Task 5 – Modifying the ServiceReferences.ClientConfig File to Support the Cookie Container Used with Forms Based Authentication

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 the Security With SharePoint And Windows Phone 7 Applications Module for more information about Forms Based Authentication.

1. In the WP7.Private.Service.PartsClient project, open the ServiceReferences.ClientConfig file.

2. Locate the ListsSoap binding element.

3. Add the following attribute to the ListsSoap binding element.

XML

enableHttpCookieContainer="true"

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

Page | 13

Page 14: Creating Private Windows Phone 7 Applications That Use ...az12722.vo.msecnd.net/.../Lab.docx  · Web viewCreating Private Windows Phone 7 Applications That Use Service Based Security

Figure 7Adding cookie support to the configuration

4. Save ServiceReferences.ClientConfig.

Task 6 – Implementing Code to Lock and Unlock the Application

In this task, you will use the cryptographic APIs to lock and unlock the windows phone application. The cryptographic APIs provide a secure mechanism to ensure the data used to unlock the phone application is valid.

1. In the WP7.Private.Service.PartsClient project, expand the Register.xaml file, and double click the Register.xaml.cs file.

2. Add the following code under the //TODO: 9.2.3 comment to define the buttonRegister_Click event handler:

C#

private void buttonRegister_Click(object sender, RoutedEventArgs e){ RegistrationService.RegistrationServiceClient registrationServiceClient = new RegistrationService.RegistrationServiceClient(); registrationServiceClient.RegisterCompleted += new EventHandler<RegistrationService.RegisterCompletedEventArgs> (registrationServiceClient_RegisterCompleted); registrationServiceClient.RegisterAsync(txtApplicationID.Text, txtApplicationPassword.Text, txtApplicationRegistrationKey.Text);}

The buttonRegister_Click event handler is called when a user clicks the Register button in the Windows Phone 7 application. The above code uses the proxy class Visual Studio 2010 generated for the RegistrationService Windows Azure WCF Service to attempt to unlock the application. First, an instance of the proxy class is created, then the RegisterCompleted event handler is defined; it fires when the RegisterAsync method completes. The application ID,

Page | 14

Page 15: Creating Private Windows Phone 7 Applications That Use ...az12722.vo.msecnd.net/.../Lab.docx  · Web viewCreating Private Windows Phone 7 Applications That Use Service Based Security

application password, and application registration key values the user entered in the textboxes are passed as arguments to the RegisterAsync method.

3. Add the following code under the //TODO: 9.2.4 comment to define the registrationServiceClient_RegisterCompleted event handler:

C#

void registrationServiceClient_RegisterCompleted(object sender, RegistrationService.RegisterCompletedEventArgs e){ if (e.Result.ToString() == "Success") { NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative)); } else { MessageBox.Show("The application could not be registered. Please verify " + "the Application ID, Application Password, and Registration Key " + "are correct and try again.", "Registration Error", MessageBoxButton.OK); } }

The above code fires when the RegisterAsync method completes. The value returned from the call to the RegistrationService is checked. If the value is Success, the user entered the correct information to unlock the application and the application opens the MainPage user control. If the value is not Success, the user entered incorrect information to unlock the application and the application prompts the user to validate their input and try again.

4. Save Register.xaml.cs.

Task 7 – Testing the Application in the Local Azure AppFabric Simulation Environment

In this task, you will test the Windows Phone 7 application with the RegistrationService running in the local Azure AppFabric simulation environment.

1. In the WP7.Private.Service.PartsClient solution, select Windows Phone 7 Emulator in the deployment location dropdown list.

2. Press F5.

3. The Windows Phone 7 application starts in the emulator prompts for the information necessary to unlock the application. The correct values are pre-filled. In a real world

Page | 15

Page 16: Creating Private Windows Phone 7 Applications That Use ...az12722.vo.msecnd.net/.../Lab.docx  · Web viewCreating Private Windows Phone 7 Applications That Use Service Based Security

scenario, the user would be required to enter values necessary to unlock the phone application.

Figure 8The application registration screen

4. Click in the Application Password textbox and enter a character.

Page | 16

Page 17: Creating Private Windows Phone 7 Applications That Use ...az12722.vo.msecnd.net/.../Lab.docx  · Web viewCreating Private Windows Phone 7 Applications That Use Service Based Security

Figure 9Entering the incorrect registration number

5. Click the Register button.

Page | 17

Page 18: Creating Private Windows Phone 7 Applications That Use ...az12722.vo.msecnd.net/.../Lab.docx  · Web viewCreating Private Windows Phone 7 Applications That Use Service Based Security

Figure 10Registration validation error

6. The Windows Phone 7 application displays an error message that the application registration failed. It does not allow you to use the rest of the application.

7. Click OK.

Page | 18

Page 19: Creating Private Windows Phone 7 Applications That Use ...az12722.vo.msecnd.net/.../Lab.docx  · Web viewCreating Private Windows Phone 7 Applications That Use Service Based Security

Figure 11Correcting the registration string

8. Click in the Application Password textbox and delete the character you entered. Click Register.

9. The Windows Phone 7 application displays the items from the Maintenance Requests SharePoint list.

Page | 19

Page 20: Creating Private Windows Phone 7 Applications That Use ...az12722.vo.msecnd.net/.../Lab.docx  · Web viewCreating Private Windows Phone 7 Applications That Use Service Based Security

Figure 12Registration successful

10. Click on one of the maintenance requests in the list to select it. The Windows Phone 7 application displays the details for the selected maintenance request from the SharePoint list.

Page | 20

Page 21: Creating Private Windows Phone 7 Applications That Use ...az12722.vo.msecnd.net/.../Lab.docx  · Web viewCreating Private Windows Phone 7 Applications That Use Service Based Security

Figure 13Maintenance task details

Page | 21

Page 22: Creating Private Windows Phone 7 Applications That Use ...az12722.vo.msecnd.net/.../Lab.docx  · Web viewCreating Private Windows Phone 7 Applications That Use Service Based Security

Exercise 4: Deploying and Testing in the Cloud

In this exercise, you will publish the RegistrationService 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 RegistrationService WCF Service for Azure publishing.

1. Return to the WP7.Private.Service Microsoft Visual Studio 2010 solution.

2. Press Shift-F5 to stop the debugger.

Note: Steps 3-7 help guarantee the Azure Deployment package is as small as possible and help to ensure the package will work once deployed to Windows Azure. You may not need to perform all of these steps in every scenario; they have been included in this lab document to ensure the deployment package will work properly.

3. In the Solution Explorer, right click the RegisterWebRole project and select Clean.

4. In the Solution Explorer, right click the RegisterWebRole project and select Build.

5. In the Solution Explorer, right click the WP7.Private.Service project and select Clean.

6. In the Solution Explorer, right click the WP7.Private.Service project and select Build.

7. In the Solution Explorer, right click the WP7.Private.Service project and select Publish.

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

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

Page | 22

Page 23: Creating Private Windows Phone 7 Applications That Use ...az12722.vo.msecnd.net/.../Lab.docx  · Web viewCreating Private Windows Phone 7 Applications That Use Service Based Security

Figure 14Deploy Windows Azure dialog

10. The service package is created in a folder named Publish inside the bin directory. You can access it from the following location:%TrainingKitPath%\ Labs\CreatingPrivateApplicationsUsingServices\Source\Before\WP7.Private.Service \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 Configuring the RegistrationService in Windows Azure

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

1. Open Internet Explorer, and go to http://windows.azure.com.

Page | 23

Page 24: Creating Private Windows Phone 7 Applications That Use ...az12722.vo.msecnd.net/.../Lab.docx  · Web viewCreating Private Windows Phone 7 Applications That Use Service Based Security

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 Hosted service by clicking the New Hosted Service from the ribbon menu.

Figure 15Create a new hosted service

3. 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. See the screenshot below for an example.

c. URL prefix of your service: This is a unique URL. Choose an available URL. See the screenshot below for an example.

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

Note: 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.

Page | 24

Page 25: Creating Private Windows Phone 7 Applications That Use ...az12722.vo.msecnd.net/.../Lab.docx  · Web viewCreating Private Windows Phone 7 Applications That Use Service Based Security

f. Deployment Name: A user-friendly name to identify the service. See the screenshot below for an example.

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 16The complete Azure Hosted Service dialog

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

Page | 25

Page 26: Creating Private Windows Phone 7 Applications That Use ...az12722.vo.msecnd.net/.../Lab.docx  · Web viewCreating Private Windows Phone 7 Applications That Use Service Based Security

Note: 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 17Azure deployment warning

5. It could take a few minutes for the production environment to be ready. The image below shows a production environment when ready. To display the DNS name information, select the RegistrationService deployment.

Page | 26

Page 27: Creating Private Windows Phone 7 Applications That Use ...az12722.vo.msecnd.net/.../Lab.docx  · Web viewCreating Private Windows Phone 7 Applications That Use Service Based Security

Figure 18Registration service deployment

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

6. Open Internet Explorer.

7. In the web browser, navigate to the RegistrationService.svc file to test the deployment.

Example: http://registrationservice.cloudapp.net/RegistrationService.svc

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

Page | 27

Page 28: Creating Private Windows Phone 7 Applications That Use ...az12722.vo.msecnd.net/.../Lab.docx  · Web viewCreating Private Windows Phone 7 Applications That Use Service Based Security

Figure 19Registration service 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 7 application to set the endpoint for the RegistrationService Windows Azure WCF Service to the production deployment you created in the previous task.

1. In the WP7.Private.Service.PartsClient project, open the ServiceReferences.ClientConfig file.

2. Locate the BasicHttpBinding_IRegistrationService endpoint element.

3. Modify the address attribute in the BasicHttpBinding_IRegistrationService endpoint element. Replace the existing address value with the URL to the RegistrationService WCF Service in Windows Azure.

XML

<endpoint address="http://<DNS Name>.cloudapp.net/RegistrationService.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IRegistrationService" contract="RegistrationService.IRegistrationService" name="BasicHttpBinding_IRegistrationService" />

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

Note: The URL will be different in your environment.

Figure 20Endpoint address modification

4. Save ServiceReferences.ClientConfig.

Page | 28

Page 29: Creating Private Windows Phone 7 Applications That Use ...az12722.vo.msecnd.net/.../Lab.docx  · Web viewCreating Private Windows Phone 7 Applications That Use Service Based Security

Task 4 – Testing the Application with the RegistrationService Windows Azure WCF Service Deployed to the Cloud

In this task, you will test the Windows Phone 7 application with the RegistrationService Windows Azure WCF Service deployed to the cloud.

1. In the WP7.Private.Service.PartsClient solution, select Windows Phone 7 Emulator in the deployment location dropdown list.

2. Press F5.

3. The Windows Phone 7 application starts in the emulator prompts for the information necessary to unlock the application. The correct values are pre-filled.

Page | 29

Page 30: Creating Private Windows Phone 7 Applications That Use ...az12722.vo.msecnd.net/.../Lab.docx  · Web viewCreating Private Windows Phone 7 Applications That Use Service Based Security

Figure 21Application registration page

4. Click in the Application Password textbox and enter a character.

Page | 30

Page 31: Creating Private Windows Phone 7 Applications That Use ...az12722.vo.msecnd.net/.../Lab.docx  · Web viewCreating Private Windows Phone 7 Applications That Use Service Based Security

Figure 22Typo in registration string

5. Click the Register button.

Page | 31

Page 32: Creating Private Windows Phone 7 Applications That Use ...az12722.vo.msecnd.net/.../Lab.docx  · Web viewCreating Private Windows Phone 7 Applications That Use Service Based Security

Figure 23Failed registration

6. The Windows Phone 7 application displays an error message that the application registration failed. It does not allow you to use the rest of the application.

7. Click OK.

Page | 32

Page 33: Creating Private Windows Phone 7 Applications That Use ...az12722.vo.msecnd.net/.../Lab.docx  · Web viewCreating Private Windows Phone 7 Applications That Use Service Based Security

Figure 24Correct registration string

8. Click in the Application Password textbox and delete the character you entered. Click Register.

9. The Windows Phone 7 application displays the items from the Maintenance Requests SharePoint list.

Page | 33

Page 34: Creating Private Windows Phone 7 Applications That Use ...az12722.vo.msecnd.net/.../Lab.docx  · Web viewCreating Private Windows Phone 7 Applications That Use Service Based Security

Figure 25Registration accepted

10. Click on one of the maintenance requests in the list to select it. The Windows Phone 7 application displays the details for the selected maintenance request from the SharePoint list.

Page | 34

Page 35: Creating Private Windows Phone 7 Applications That Use ...az12722.vo.msecnd.net/.../Lab.docx  · Web viewCreating Private Windows Phone 7 Applications That Use Service Based Security

Figure 26Maintenance Request details

Summary

In this hands-on lab, you saw how to lock a Windows Phone 7 application with the crypotographic APIs available to Windows Azure WCF services. You also learned how to use a Windows Azure WCF Service

Page | 35

Page 36: Creating Private Windows Phone 7 Applications That Use ...az12722.vo.msecnd.net/.../Lab.docx  · Web viewCreating Private Windows Phone 7 Applications That Use Service Based Security

to implement the application verification. Finally, you learned how to provide users the functionality they need to unlock the application.

Page | 36