Integrating SharePoint and Windows Phone 7 …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows...

42
Hands-On Lab Integrating SharePoint and Windows Phone 7 Notifications Lab version: 1.0.0 Last updated: 6/30/2022 Page | 1

Transcript of Integrating SharePoint and Windows Phone 7 …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows...

Page 1: Integrating SharePoint and Windows Phone 7 …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications can use Windows Push Notification Services to notify users

Hands-On LabIntegrating SharePoint and Windows Phone 7 Notifications

Lab version: 1.0.0

Last updated: 5/24/2023

Page | 1

Page 2: Integrating SharePoint and Windows Phone 7 …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications can use Windows Push Notification Services to notify users

CONTENTS

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

EXERCISE 1: CREATING A SHAREPOINT LIST DATA SOURCE...........................................................4Task 1 – Creating the Maintenance Training Calendar List..................................................................4

EXERCISE 2: VERIFYING THE NOTIFICATION REGISTRATION WCF SERVICE..................................5Task 1 – Beginning the Exercise...........................................................................................................6

Task 2 – Running the Service in Visual Studio 2010.............................................................................6

EXERCISE 3: CREATING THE LIST EVENT RECEIVER TO SEND NOTIFICATIONS............................7Task 1 – Adding the EventNotification Project to the Solution............................................................7

Task 2 – Completing the Notification.cs Class to Send Toast Notifications..........................................8

Task 3 – Completing the EventListNotification.cs Class to Send Toast Notifications.........................10

Task 4 – Adding a Reference to the NotificationRegistration WCF Service........................................10

Task 5 – Verifying the Event Receiver Builds and Deploys Correctly..................................................12

EXERCISE 4: CREATING THE WINDOWS PHONE 7 APPLICATION...................................................14Task 1 – Adding the WP7.Notification.Events.PhoneApp Project to the Solution.............................14

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

Task 3 – Completing the SettingsViewModel.cs Class........................................................................16

Task 4 – Completing the MainPage.xaml.cs File................................................................................20

Task 5 – Adding a Reference to the SharePoint Lists.asmx Web Service...........................................20

Task 6 – Adding a Reference to the NotificationRegistration WCF Service........................................21

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

EXERCISE 5: TESTING THE WINDOWS PHONE 7 APPLICATION.......................................................23Task 1 – Testing the Application’ View Functionality in Windows Phone 7 Emulator........................23

Task 2 -Testing the Toast Notification in Windows Phone 7 Emulator..............................................25

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

Page | 2

Page 3: Integrating SharePoint and Windows Phone 7 …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications can use Windows Push Notification Services to notify users

Overview

Windows Phone 7 applications can use Windows Push Notification Services to notify users of custom events. Windows Phone 7 applications integrating with SharePoint can use notifications to alert users about changes in SharePoint data sources.

Objectives

In this hands-on lab, you will learn how to create a list event handler that will send Push Notifications to a Windows Phone 7 application. You will alow learn how to register for notifications and bind the phone and application to a toast notification.

Learn how to use a SharePoint list event reciever to create notifications for registered devices.

Learn how register a device with a custom WCF service to subscribe to notifications.

Learn how to subscribe to and bind to notifictions in a 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 Modulefor 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: Integrating SharePoint and Windows Phone 7 …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications can use Windows Push Notification Services to notify users

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

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

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

Internet connectivity

Note: This lab requires the firewall be turned off to enable connection to the Push Notification Service.

Exercise 1: Creating a SharePoint List Data Source

In this exercise, you will create a new calendar list that will contain training events. In this scenario, the Windows Phone 7 application will read the calender list and display the events it contains. The Windows Phone 7 application allows users to receive Toast notifications when items in the calendar list are added, modified or deleted. Users with write permissions will be able to add events to the calendar list to test the applciation.

Task 1 – Creating the Maintenance Training Calendar List

In this task, you will use the calendar list template to create the maintenance training schedule 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.

Page | 4

Page 5: Integrating SharePoint and Windows Phone 7 …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications can use Windows Push Notification Services to notify users

4. In the Filter By section, select List.

5. Select the Calendar list.

Figure 1Selecting a Calendar list template.

6. In the Name textbox, enter Maintenance Training Schedule.

7. Click Create.

Exercise 2: Verifying the Notification Registration WCF Service

Page | 5

Page 6: Integrating SharePoint and Windows Phone 7 …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications can use Windows Push Notification Services to notify users

In this exercise, you will verify an existing registration WCF service builds and runs in your development environment. The WCF service manages the notification registrations. It uses a static collection to maintain the notification registrations.

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.

3. Browse to the WP7.Notification.Events.sln file located at %TrainingKitPath%\Labs\IntegratingNotifications\Source\Before and select it.

4. Click Open to open the solution.

Task 2 – Running the Service in Visual Studio 2010

In this task, you will run the NotificationRegistration service to verify it starts correctly.

1. In the Solution Explorer, in the NotificationRegistration project, right click ListNotificationChannels.svc and select Set as Start Page.

2. Press F5 to run the service. The service should start in the WCF Test Harness or display the Service page in the web browser.

Figure 2NotificationRegistration WCF Test Client

Page | 6

Page 7: Integrating SharePoint and Windows Phone 7 …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications can use Windows Push Notification Services to notify users

Figure 3NotificationRegistration WCF Services in Internet Explorer

3. In Visual Studio, press Shift + F5 to stop debugging.

Exercise 3: Creating the List Event Receiver to Send Notifications

In this exercise, you will create a list event receiver to send toast notifications to registered devices. The list event receiver will be associated with calendar lists.

Task 1 – Adding the EventNotification Project to the Solution

In this task, you add the existing EventNotification project to the solution.

1. In the Solution Explorer, right-click WP7.Notification.Events and select Add | Existing Project.

2. Browse to EventNotification.csproj located in the EventNotification folder.

3. Click Open.

Page | 7

Page 8: Integrating SharePoint and Windows Phone 7 …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications can use Windows Push Notification Services to notify users

Figure 4Solution Explorer with WCF Service project and Event Receiver project

Task 2 – Completing the Notification.cs Class to Send Toast Notifications

In this task, you will complete the existing Notification class to send toast notification to any devices registered for notification.

1. In the EventNotification project, open the Notification.cs file.

2. Add the following code under the //TODO: 7.1.1 comment to define the SendNotification method:

C#

public static void SendNotification(string channelUri, string text1, string text2){ string ToastPushXML = "<?xml version='1.0' encoding='utf-8'?>" + "<wp:Notification xmlns:wp='WPNotification'>" + "<wp:Toast>" + "<wp:Text1>{0}</wp:Text1>" + "<wp:Text2>{1}</wp:Text2>" + "</wp:Toast>" + "</wp:Notification>";

string str = string.Format(ToastPushXML, text1, text2);

HttpWebRequest sendNotificationRequest = (HttpWebRequest)WebRequest.Create(channelUri); sendNotificationRequest.Method = "POST"; sendNotificationRequest.Headers = new WebHeaderCollection(); sendNotificationRequest.ContentType = "text/xml"; sendNotificationRequest.Headers.Add("X-NotificationClass", "2"); sendNotificationRequest.Headers.Add("X-WindowsPhone-Target", "toast"); byte[] strBytes = new UTF8Encoding().GetBytes(str); sendNotificationRequest.ContentLength = strBytes.Length;

using (Stream requestStream = sendNotificationRequest.GetRequestStream())

Page | 8

Page 9: Integrating SharePoint and Windows Phone 7 …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications can use Windows Push Notification Services to notify users

{ requestStream.Write(strBytes, 0, strBytes.Length); }

try { var response = (HttpWebResponse)sendNotificationRequest.GetResponse(); var notiticationStatus = response.Headers["X-NotificationStatus"]; var notitificationChannelStatus = response.Headers["X-SubscriptionStatus"]; var deviceConnectionStatus = response.Headers["X-DeviceConnectionStatus"]; } catch { // Ignoring the response. // In a production application you should review the response and // code appropriate for the specific response. // http://msdn.microsoft.com/en-us/library/ff941100%28v=VS.92%29.aspx } }

The above code creates a HttpWebRequest object and posts XML to the channel Uri provided to the method. This method is called once for each channel (device) that is registered for notification with a matching list id.l The XMLpayload defines the type of notification (Toast) as well as the details of the notification ( text1 and text 2). A Toast notification accepts two text fields. Push Notification Services requires the additional header values included in the above code.

3. Add the following code under the //TODO: 7.1.2 comment to define the Notify method:

C#

public static void Notify(string listId, string text1, string text2){ NotificationRegistration.ListNotificationChannels svc = new NotificationRegistration.ListNotificationChannels(); string[] channelUris = svc.RetrieveChannelURIsForListId(listId);

foreach (var channel in channelUris) { SendNotification(channel, text1, text2); }}

Page | 9

Page 10: Integrating SharePoint and Windows Phone 7 …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications can use Windows Push Notification Services to notify users

The above code uses the proxy class Visual Studio 2010 generated for the NotificationRegistration WCF service to retrieve an array of channel URIs for any device registered for notifications for this specific list id. There will be one entry for each channel (device) registered for notifications for the list. This method will call the SendNotification method for each channel returned from the registration service.

4. Save and close the Notification.cs file.

Task 3 – Completing the EventListNotification.cs Class to Send Toast Notifications

In this task, you will complete the existing EventListNotification class to send a Toast notification to any devices registered for notification.

1. In the EventNotification project, open the EventListNotification.cs file located in the EventListNotification SharePoint Project Item.

2. Add the following code under the //TODO: 7.1.3 comment to define the Notify method:

C#

private void Notify(SPItemEventProperties properties, string eventName){ string listId = properties.ListId.ToString(); string listTitle = properties.List.Title; Notification.Notify(listId, string.Format("{0}: ", listTitle), string.Format("Item: {0}", eventName)); }

The above code is called by the specific events in the receiver class. The code will call the static Notify method of the Notification class passing in the list id and the values for the notification’s text message. For each notified event of the event receiver, the receiver code will send notifications to devices registered for notifications for this list.

3. Save and close the EventListNotification.cs file.

Task 4 – Adding a Reference to the NotificationRegistration WCF Service

In this task, you will add a reference to the NotificationRegistration WCF service.

1. In the Solution Explorer, in the EventNotification project, right click Service References and select Add Service Reference.

2. Click Advanced…

3. Click Add Web Reference…

4. Click Web services in this solution

Page | 10

Page 11: Integrating SharePoint and Windows Phone 7 …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications can use Windows Push Notification Services to notify users

Figure 5Selecting Web Services in this solution

5. Click ListNotificationChannels

Figure 6Selecting the ListNotificationChannels service

6. In the Web reference name textbox enter NotificationRegistration.

Page | 11

Page 12: Integrating SharePoint and Windows Phone 7 …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications can use Windows Push Notification Services to notify users

Figure 7Entering the Web reference name for the service

7. Click Add Reference.

Task 5 – Verifying the Event Receiver Builds and Deploys Correctly.

In this task, you verify the event receiver and WCF service builds and deploys correctly.

1. In the Solution Explorer, right click the WP7.Notification.Events solution and select Properties.

2. Select Multiple startup projects.

3. Set the action for EventNotification to Start.

4. Set the action for NotificationRegistration to Start.

Page | 12

Page 13: Integrating SharePoint and Windows Phone 7 …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications can use Windows Push Notification Services to notify users

Figure 8Selecting multiple startup objects in Visual Studio 2010

5. Click OK.

6. In the Solution Explorer, select the EventNotification project.

7. Set the Site URL property to the site containing the Maintenance Training Schedule list.

Page | 13

Page 14: Integrating SharePoint and Windows Phone 7 …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications can use Windows Push Notification Services to notify users

Figure 9Setting the Site URL for the event receiver project

8. In the WP7.Notification.Events solution, press F5.

9. Verify the solution builds and deploys without error.

10. In the WP7.Notification.Events solution, press Shift + F5 to stop debugging.

Exercise 4: Creating the Windows Phone 7 Application

In this exercise, you will create a Windows Phone 7 application to read from the list created in Exercise 1. The application will allow users to opt in for notifications. The application will enable and disable toast notifications based on the setting.

Task 1 – Adding the WP7.Notification.Events.PhoneApp Project to the Solution

In this task, you add the existing WP7.Notification.Events.PhoneApp project to the solution.

1. In the Solution Explorer, right-click the WP7.Notification.Events solution, and select Add | Existing Project.

2. Browse to WP7.Notification.Events.PhoneApp.csproj located in the PhoneApp folder.

3. Click Open.

Page | 14

Page 15: Integrating SharePoint and Windows Phone 7 …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications can use Windows Push Notification Services to notify users

Figure 10Solution Explorer with three projects displayed

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.Notification.Events.PhoneApp 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 read and write 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 LIST_TITLE constant to Maintenance Training Schedule.

5. Change the LIST_ID constant to the list id of the Maintenance Training Schedule.

a. Open the Maintenance Training Schedule list in Internet Explorer.

b. Select the Calendar Ribbon tab.

c. Click List Settings Ribbon button.

d. Select the value of the List URL parameter from the browser’s address bar.

e. The value of the list id in the address bar is URL encoded. Remove the %7B and %7D values at the beginning and end of the parameter. Replace %2D with the dash character.

Page | 15

Page 16: Integrating SharePoint and Windows Phone 7 …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications can use Windows Push Notification Services to notify users

For example:

%7B618FD6BA%2DE587%2D4C93%2D9143%2DD21B2C01E8AD%7D

Is converted to:

618FD6BA-E587-4C93-9143-D21B2C01E8AD

f. Copy the unencoded list id to the LIST_ID constant value.

C#

public const string LIST_ID = "618FD6BA-E587-4C93-9143-D21B2C01E8AD";

Note: If the list id constant is not correct, the event handler will not receive the channel Uri (device) from the registration service.

Note: The above code is an example. You must use your unique list id.

Task 3 – Completing the SettingsViewModel.cs Class

In this task, you will complete the existing SettingsViewModel class. This class manages the application’s connection and bindings for notification.

1. In the Solution Explorer, open the SettingsViewModel.cs file located in the ViewModels folder.

2. Add the following code under the //TODO: 7.1.4 comment to define the Current property:

C#

private static SettingsViewModel current;public static SettingsViewModel Current{ get { return current; }}

The above code creates a singleton-type property. This allows the code to have only one instance of this class at a time. This view model class contains the code to manage notifications. Creating a singleton of this class allows the code to be available at all times.

3. Add the following code under the //TODO: 7.1.5 comment to define the IsNotificationEnabled property.

Page | 16

Page 17: Integrating SharePoint and Windows Phone 7 …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications can use Windows Push Notification Services to notify users

C#

public bool IsNotificationEnabled{ get { if (settings.Contains(Constants.IS_NOTIFICATION_ENABLED)) { return (bool)settings[Constants.IS_NOTIFICATION_ENABLED]; } else { settings.Add(Constants.IS_NOTIFICATION_ENABLED, false); return false; } } set { if (settings.Contains(Constants.IS_NOTIFICATION_ENABLED)) { settings[Constants.IS_NOTIFICATION_ENABLED] = value; } else { settings.Add(Constants.IS_NOTIFICATION_ENABLED, value); } if (value == true) { EnableNotifications(); } else { DisableNotifications(); }

UpdateNotificationBindings(); RaisePropertyChanged("IsNotificationEnabled", this, PropertyChanged); }}

The IsNotificationEnabled property is persisted in isolated storage. This value is bound to the Settings.xaml view. When the user enables or disables notifications in the user interface or when the application starts the IsNotification value is set and the code will set the correct bindings. When the end user opts to enable notifications, the property configures the notifications on the phone..

Page | 17

Page 18: Integrating SharePoint and Windows Phone 7 …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications can use Windows Push Notification Services to notify users

4. Add the following code under the //TODO: 7.1.6 comment to define the SettingsViewModel contstructor.

C#

public SettingsViewModel(){ if (current != null) { throw new InvalidOperationException("Only 1 SettingsViewModel Allowed"); } settings = IsolatedStorageSettings.ApplicationSettings; current = this;}

The above code creates the view model and sets the current variable to the newly created object. This creates our singleton object.

5. Add the following code under the //TODO: 7.1.7 comment to define the EnableNotifications method.

C#

public void EnableNotifications(){ Channel = HttpNotificationChannel.Find(Constants.CHANNEL_NAME); if (Channel == null) { Channel = new HttpNotificationChannel(Constants.CHANNEL_NAME); Channel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(Channel_ChannelUriUpdated); Channel.Open(); } else { Channel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(Channel_ChannelUriUpdated); ChannelUri = Channel.ChannelUri; UpdateNotificationBindings(); }}

Page | 18

Page 19: Integrating SharePoint and Windows Phone 7 …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications can use Windows Push Notification Services to notify users

The above code will attempt to find an existing HTTPNotificationChannel. The HTTPNotificationChannel object contains information about the persistant channel between the application, the phone OS and the Microsoft Push Notification service. Channels are defined using a channel name. The application will create a new channel if an existing channel is not found. Once there is a channel available, the code will update the notification bindings by calling UpdateNotificationBindings.

6. Add the following code under the //TODO: 7.1.8 comment to define the RegisterWithNotificationSource method.

C#

internal void RegisterWithNotificationSource(Uri channelUri){ var svc = new NotificationRegistration.ListNotificationChannelsClient(); svc.RegisterAsync(channelUri.ToString(), Constants.LIST_ID);}

The above code will use the service proxy created by Visual Studio to register the device’s channel URI with the NotificationRegistration WCF service after the application has a channel. The registration service tracks which notification channels (device) are listening to notifications. In this application, the registration service tracks the channel Uri and an associated list id.

7. Add the following code under the //TODO: 7.1.9 comment to define the UpdateNotificationBindings method.

C#

private void UpdateNotificationBindings(){ if (IsNotificationEnabled) { if (Channel != null && !Channel.IsShellToastBound) { Channel.BindToShellToast(); } } else { if (Channel.IsShellToastBound) { Channel.UnbindToShellToast(); } } }

Page | 19

Page 20: Integrating SharePoint and Windows Phone 7 …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications can use Windows Push Notification Services to notify users

The above code will bind or unbind the device to the toast notifications. When bound, this code alerts the phone that it is listening for toast notifications. When not bound to the toast notifications the phone will not display a toast notification sent from the Push Notification Service. Developers do not have access to modify the toast displayed by the phone. When bound to the toast notification the user interface will display a toast with the text sent in the Xml payload.

8. Save and close SettingsViewModel.cs file.

Task 4 – Completing the MainPage.xaml.cs File

In this task, you will complete the MainPage.xaml.cs file.

1. In the Solution Explorer, in the WP7.Notification.Events.PhoneApp project, right click MainPage.xaml and select View Code.

2. Add the following code under the //TODO: 7.1.10 comment to define the MainPage constructor method.

C#

public MainPage(){ InitializeComponent(); viewModel = new MainViewModel(); DataContext = viewModel; viewModel.GetEvents();

App.settingsViewModel = new SettingsViewModel();

var settings = SettingsViewModel.Current;

if (settings.IsNotificationEnabled) { settings.EnableNotifications(); } }

The above constructor code sets the viewModel and DataContext for the main page. The code creates the single SettingsViewModel object and determines if notifications are enabled. If notifications are enabled it calls the EnableNotifications method of the SettingsViewModel to create and configure the notification channel. This sets the state of the application whenever it is executed

3. Save and close MainPage.Xaml.cs.

Task 5 – Adding a Reference to the SharePoint Lists.asmx Web Service

Page | 20

Page 21: Integrating SharePoint and Windows Phone 7 …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications can use Windows Push Notification Services to notify users

In this task, you will add a reference to the SharePoint lists.asmx Web service. Lists.asmx is used to query the list and display items in the application.

1. In the Solution Explorer, in the WP7.Notification.Events.PhoneApp project, right click Service References and select Add Service Reference.

2. In the Address textbox enter the URL to the lists.asmx SharePoint web service for the site where you created the Maintenance Training Schedule list.

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

3. Click Go.

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

5. Click OK.

Task 6 – Adding a Reference to the NotificationRegistration WCF Service

In this task, you will add a reference to the NotificationRegistration WCF service. The WCF service is used to register the device’s channel Uri (from Push Notification Service) and list id. The WCF service is a custom WCF service that we use to determine who should be notified of events for each list.

1. In the Solution Explorer, in the WP7.Notification.Events.PhoneApp project, right click Service References and select Add Service Reference.

2. Click Discover.

3. After the ListNotificationChannelsSvc service is discovered, enter NotificationRegistration in the Namespace textbox.

4. Click OK.\

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

In this task, you will modify the ServiceReferences.ClientConfig 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.Notification.Events.PhoneApp project, open the ServiceReferences.ClientConfig file.

2. Locate the ListsSoap binding element.

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

Page | 21

Page 22: Integrating SharePoint and Windows Phone 7 …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications can use Windows Push Notification Services to notify users

XML

enableHttpCookieContainer="true"

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

Figure 11Adding the enableHttpCookieContainer in the ServiceReferences.ClientConfig file

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

Figure 12Error message received when editing a service with the enableHttpCookieContainer attribute

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 | 22

Page 23: Integrating SharePoint and Windows Phone 7 …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications can use Windows Push Notification Services to notify users

Exercise 5: Testing the Windows Phone 7 Application

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

Note: This lab requires the Windows firewall to be turned off to enable connections to the Push Notification Service.

Note: Running this code in the emulator can cause a race condition when the project debugging has stopped but the emulator has not been shut down completely. The phone application will attempt to register before the service has completely started. To avoid this error simply disable notifications and re-enable notifications when the service has started or stop debugging in Visual Studio 2010, close the emulator and restart debugging

Task 1 – Testing the Application’ View Functionality in Windows Phone 7 Emulator

In this task, you will test the Windows Phone 7 application using the Windows Phone 7 emulator.

1. In the WP7.Notification.Events.PhoneApp project, select Windows Phone 7 Emulator in the deployment location dropdown list.

2. In the Solution Explorer, right click the WP7.Notification.Events solution and select Properties.

3. Select Multiple startup projects.

4. Set the action for EventNotification to Start.

5. Set the action for NotificationRegistration to Start.

6. Set the action for WP7.Notification.Events.PhoneApp to Start.

7. Click OK.

8. In the WP7.Notification.Events solution, press F5.

9. The Windows Phone application starts in the emulator and displays the items from the Maintenance Training Schedule SharePoint list. There will be no items in the list or application until we add items to the list. The event receiver is deployed and activated. The WCF service will start and display the WCF Test Client.

Page | 23

Page 24: Integrating SharePoint and Windows Phone 7 …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications can use Windows Push Notification Services to notify users

Figure 13Application main page with no events displayed

Page | 24

Page 25: Integrating SharePoint and Windows Phone 7 …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications can use Windows Push Notification Services to notify users

Task 2 -Testing the Toast Notification in Windows Phone 7 Emulator

In this task, you will test the notification by enabling notifications and adding an item to the Maintenance Training Schedule list.

1. In the WP7.Notification.Events solution, press F5, if the application is not running.

2. The Windows Phone application and WCF Service start. The Event Receiver is deployed and activated. The emulator displays the items from the Maintenance Training Schedule SharePoint list.

3. Click the Settings icon.

Page | 25

Page 26: Integrating SharePoint and Windows Phone 7 …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications can use Windows Push Notification Services to notify users

Figure 14Settings icon on main page

4. Click Enable Notification checkbox.

Page | 26

Page 27: Integrating SharePoint and Windows Phone 7 …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications can use Windows Push Notification Services to notify users

Figure 15Application’s settings page

5. Click the phone’s back arrow button to return to the application’s main page.

Page | 27

Page 28: Integrating SharePoint and Windows Phone 7 …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications can use Windows Push Notification Services to notify users

6. Click the phone’s back arrow button to return to the tile page.

7. Click the Arrow icon in the top-right corner to display the list of applications.

Figure 16Icon to the list of applications

Page | 28

Page 29: Integrating SharePoint and Windows Phone 7 …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications can use Windows Push Notification Services to notify users

8. Left-click and hold the mouse button down on the WP7.Notification.Event application item in the list to display the menu items.

Figure 17Pinning the tile to the start page

Page | 29

Page 30: Integrating SharePoint and Windows Phone 7 …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications can use Windows Push Notification Services to notify users

9. Click pin to start.

Figure 18Application tile pinned to the start page

Page | 30

Page 31: Integrating SharePoint and Windows Phone 7 …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications can use Windows Push Notification Services to notify users

10. Leave the emulator running and return to the web browser displaying the site with your list. Visual Studio will have opened a new browser window to the start site of the project.

11. Use Internet Explorer to navigate to the Maintenance Training Schedule list and enter a new training event.

Figure 19Creating a new training event in SharePoint 2010

12. Save the new calender event.

13. Verify the toast notification is displayed on the emulator.

Note: The notification may not display immediately.

Page | 31

Page 32: Integrating SharePoint and Windows Phone 7 …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications can use Windows Push Notification Services to notify users

Figure 20Display the toast notification on the start page

14. Click the Toast message to open the application.

Page | 32

Page 33: Integrating SharePoint and Windows Phone 7 …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications can use Windows Push Notification Services to notify users

Figure 21Clicking the toast opens the application

Page | 33

Page 34: Integrating SharePoint and Windows Phone 7 …az12722.vo.msecnd.net/.../Lab.docx · Web viewWindows Phone 7 applications can use Windows Push Notification Services to notify users

Summary

In this hands-on lab, you saw how to use a SharePoint list event reciever to create toast notifications for registered phone applications. You learned how to configure a phone application to subscribe to a notification using a WCF service and how bind the device to toast notifications.

Page | 34