43
Hands-On Lab Integrating SharePoint and Windows Phone 7 Tile Notifications Lab version: 1.0.0 Last updated: 7/9/2022 Page | 1

Integrating SharePoint and Windows Phone 7 Tile …az12722.vo.msecnd.net/.../integratingtilenotificationsla… · Web viewWindows Phone 7 applications can use Windows Push Notification

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Integrating SharePoint and Windows Phone 7 Tile …az12722.vo.msecnd.net/.../integratingtilenotificationsla… · Web viewWindows Phone 7 applications can use Windows Push Notification

Hands-On LabIntegrating SharePoint and Windows Phone 7 Tile Notifications

Lab version: 1.0.0

Last updated: 5/24/2023

Page | 1

Page 2: Integrating SharePoint and Windows Phone 7 Tile …az12722.vo.msecnd.net/.../integratingtilenotificationsla… · Web viewWindows Phone 7 applications can use Windows Push Notification

CONTENTS

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

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

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

Task 2 – Adding a Count Property to the ListNotificationRegistration Class........................................6

Task 3 – Declaring Service Methods to Manage the Count.................................................................6

Task 4 – Implementing the New Service Methods...............................................................................7

Task 5 – Implementing the Method to Send a Tile Notification with a Zero Count.............................8

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

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

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

Task 3 – Adding a Reference to the NotificationRegistration WCF Service........................................13

Task 4 – Verifying the Event Receiver Builds and Deploys Correctly..................................................14

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

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

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

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

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

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

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.......................................................22Task 1 – Testing the Application’s View Functionality in Windows Phone 7 Emulator......................23

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

SUMMARY................................................................................................................................................ 35

Page | 2

Page 3: Integrating SharePoint and Windows Phone 7 Tile …az12722.vo.msecnd.net/.../integratingtilenotificationsla… · Web viewWindows Phone 7 applications can use Windows Push Notification

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 of changes in SharePoint data sources. Tile notifications can display a count of events such as the number of changes to a SharePoint list.

Objectives

In this hands-on lab, you will learn how to create a list event handler that will send tile notifications with count information. You will learn how to to register for notifications and bind the phone and application to a tile notification. You will learn how to manage counts for each subsciber.

Learn how to use a SharePoint list event reciever to create tile notifications with count information.

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

Learn how to manage event counts per registration.

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: Integrating SharePoint and Windows Phone 7 Tile …az12722.vo.msecnd.net/.../integratingtilenotificationsla… · Web viewWindows Phone 7 applications can use Windows Push Notification

◦ 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 calendar and display the events stored in it. The Windows Phone 7 application allows users to receive Toast notifications when items in the list are added, modified or deleted. Users with write permissions will be able to add events to the list to test the application.

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.

Note: If you have created the list from Integrating SharePoint and Windows Phone 7 Notifications Lab of the Integrating Push Notifications with SharePoint Data in Windows Phone 7 Applications Module then you can reuse the Maintenance Training Scheduling list from Lab 1 and skip to Exercise 2.

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

example: http://fbawp7

Page | 4

Page 5: Integrating SharePoint and Windows Phone 7 Tile …az12722.vo.msecnd.net/.../integratingtilenotificationsla… · Web viewWindows Phone 7 applications can use Windows Push Notification

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 Calendar list.

Figure 1Selecting a Calendar list template.

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

7. Click Create.

Exercise 2: Complete the Notification Registration WCF Service

Page | 5

Page 6: Integrating SharePoint and Windows Phone 7 Tile …az12722.vo.msecnd.net/.../integratingtilenotificationsla… · Web viewWindows Phone 7 applications can use Windows Push Notification

In this exercise, you will add methods to the existing registration WCF service to manage the notification count for each registration.

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\IntegratingTileNotifications\Source\Before and select it.

4. Click Open to open the solution.

Task 2 – Adding a Count Property to the ListNotificationRegistration Class

In this task, you will add an integer property to the existing ListNotificationRegistration class.

1. In the NotificationRegistration project, open the ListNotificationRegistration.cs file located in the Model folder.

2. Add the following code under the //TODO: 7.2.1 comment to define the CurrentCount property:

C#

int count;public int CurrentCount{ get { return count; } set { count = value; }}

The above property is used to maintain the current count of notifications that have been sent since the last time the phone application has cleared the count.

3. Save and close the ListNotificationRegistration.cs file.

Task 3 – Declaring Service Methods to Manage the Count

In this task, you will complete the existing IListNotificationChannels.cs interface to include the required methods declarations to manage the notification count for each registrations.

1. In the NotificationRegistration project, open the IListNotificationChannels.cs file.

2. Add the following code under the //TODO: 7.2.2 comment to define the following two method declarations:

C#

Page | 6

Page 7: Integrating SharePoint and Windows Phone 7 Tile …az12722.vo.msecnd.net/.../integratingtilenotificationsla… · Web viewWindows Phone 7 applications can use Windows Push Notification

[OperationContract] void ClearRegistrationCount(string channelUri, string listId);

[OperationContract]List<ListNotificationRegistration> RetrieveChannelURIsForListIdWithCountIncrement(string listId);

The above code defines the two methods used to clear a registration count and increment a registration count. The OperationContract attribute decorates these methods to expose the methods as part of the public interface.

Task 4 – Implementing the New Service Methods

In this task, you will complete the existing ListNotificationChannels class to include the declared interface methods from Task 3.

1. In the NotificationRegistration project, open the ListNotificationChannels.svc file.

2. Add the following code under the //TODO: 7.2.3 comment to define the RetrieveChannelURIsForListIdWithCountIncrement method:

C#

public List<ListNotificationRegistration> RetrieveChannelURIsForListIdWithCountIncrement(string listId){ var items = from r in ListNotificationRegistrations where r.ListId.ToLower() == listId.ToLower() select r;

List<ListNotificationRegistration> notifications = items.ToList(); notifications.ForEach(n => n.CurrentCount++);

return notifications;}

The above code uses Linq to retrieve the registrations for the specific list id. It then increments each registration by one and returns the ListNotificationRegistration collection. The event receiver will call this method for each event managed by the event receiver.

3. Add the following code under the //TODO: 7.2.4 comment to define the ClearRegistrationCount method:

C#

public void ClearRegistrationCount(string channelUri, string listId){ var reg = (from r in ListNotificationRegistrations

Page | 7

Page 8: Integrating SharePoint and Windows Phone 7 Tile …az12722.vo.msecnd.net/.../integratingtilenotificationsla… · Web viewWindows Phone 7 applications can use Windows Push Notification

where r.ChannelUri.ToLower() == channelUri.ToLower() && r.ListId.ToLower() == listId.ToLower() select r).SingleOrDefault<ListNotificationRegistration>(); if (reg != null) { reg.CurrentCount = 0; Notification.SendNewTile(channelUri); }}

The above code uses Linq to retrieve a single ListNotificationRegistration object for the specific channel Uri and list id. If a matching ListNotificationRegistration is found the CurrentCount is set to zero and the service will send a new tile notification with a zero count. A zero count will remove the counter from the tile located on the phone. This method is called by the phone application each time the application starts.

Task 5 – Implementing the Method to Send a Tile Notification with a Zero Count

In this task, you will complete the existing Notification class to send a tile notification to a specific channel Uri with a zero count.

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

2. Add the following code under the //TODO: 7.2.5 comment to define the SendNewTile method:

C#

public static void SendNewTile(string channelUri){ string tilePushXml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<wp:Notification xmlns:wp=\"WPNotification\">" + "<wp:Tile>" + "<wp:Count>0</wp:Count>" + "</wp:Tile> " + "</wp:Notification>"; HttpWebRequest sendNotificationRequest = (HttpWebRequest)WebRequest.Create(channelUri); sendNotificationRequest.Method = "POST"; sendNotificationRequest.Headers = new WebHeaderCollection(); sendNotificationRequest.ContentType = "text/xml"; sendNotificationRequest.Headers.Add("X-NotificationClass", "1"); sendNotificationRequest.Headers.Add("X-WindowsPhone-Target", "token"); byte[] strBytes = new UTF8Encoding().GetBytes(tilePushXml); sendNotificationRequest.ContentLength = strBytes.Length;

Page | 8

Page 9: Integrating SharePoint and Windows Phone 7 Tile …az12722.vo.msecnd.net/.../integratingtilenotificationsla… · Web viewWindows Phone 7 applications can use Windows Push Notification

using (Stream requestStream = sendNotificationRequest.GetRequestStream()) { 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 an HttpWebRequest object and posts XML to the channel uri provided to the method. The XML defines the type of notification as well as the details of the notification. A Tile notification can set the count, background image and the text of the title. This method sends the static count of zero to the phone. A count of zero will remove the counter from the tile.

The notification is sent using the channel Uri. It is sent to the Push Notification Service which sends the message to the device using the connection between the device and Push Notification Service. This notification will clear the count from the application tile.

Task 6 – 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.

Page | 9

Page 10: Integrating SharePoint and Windows Phone 7 Tile …az12722.vo.msecnd.net/.../integratingtilenotificationsla… · Web viewWindows Phone 7 applications can use Windows Push Notification

Figure 2NotificationRegistration WCF Test Client

Figure 3NotificationRegistration WCF Services in Internet Explorer

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

Page | 10

Page 11: Integrating SharePoint and Windows Phone 7 Tile …az12722.vo.msecnd.net/.../integratingtilenotificationsla… · Web viewWindows Phone 7 applications can use Windows Push Notification

Exercise 3: Creating the List Event Receiver to Send Notifications

In this exercise, you will create the SharePoint list event receiver to send tile notifications with a notification count to registered devices. The SharePoint 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 the WP7.Notification.Events solution, and select Add | Existing Project.

2. Browse to EventNotification.csproj located in the EventNotification folder and select it.

3. Click Open.

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

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

In this task, you will complete the existing Notification class to send a 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.2.6 comment to define the SendNotification method:

C#

public static void SendNotification(string channelUri, int count){ string tilePushXml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<wp:Notification xmlns:wp=\"WPNotification\">" + "<wp:Tile>" + "<wp:Count>{0}</wp:Count>" +

Page | 11

Page 12: Integrating SharePoint and Windows Phone 7 Tile …az12722.vo.msecnd.net/.../integratingtilenotificationsla… · Web viewWindows Phone 7 applications can use Windows Push Notification

"</wp:Tile> " + "</wp:Notification>";

string tilePushXmlFormatted = string.Format(tilePushXml, count);

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

using (Stream requestStream = sendNotificationRequest.GetRequestStream()) { 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. The XML defines the type of notification as well as the details of the notification. A Tile notification can set the count, background image and the text of the title. This method will

Page | 12

Page 13: Integrating SharePoint and Windows Phone 7 Tile …az12722.vo.msecnd.net/.../integratingtilenotificationsla… · Web viewWindows Phone 7 applications can use Windows Push Notification

send the phone a count value based on the passed in parameter value. This method is similar to the SendNotification method located in the WCF registration service. The difference is that this method adds the current count to the notification instead of sending a default count of 0.

The Xml payload is sent to the Push Notification Service which then send the notification to the device using the channel between the device and the Push Notification Service.

Task 3 – 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

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

Page 14: Integrating SharePoint and Windows Phone 7 Tile …az12722.vo.msecnd.net/.../integratingtilenotificationsla… · Web viewWindows Phone 7 applications can use Windows Push Notification

Figure 7Entering the Web reference name for the service

7. Click Add Reference.

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

In this task, you verify the event receiver and WCF service build and deploy 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 | 14

Page 15: Integrating SharePoint and Windows Phone 7 Tile …az12722.vo.msecnd.net/.../integratingtilenotificationsla… · Web viewWindows Phone 7 applications can use Windows Push Notification

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

Page 16: Integrating SharePoint and Windows Phone 7 Tile …az12722.vo.msecnd.net/.../integratingtilenotificationsla… · Web viewWindows Phone 7 applications can use Windows Push Notification

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 tile notification based on the setting. The tile notification will include a count value.

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

Page 17: Integrating SharePoint and Windows Phone 7 Tile …az12722.vo.msecnd.net/.../integratingtilenotificationsla… · Web viewWindows Phone 7 applications can use Windows Push Notification

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

Page 18: Integrating SharePoint and Windows Phone 7 Tile …az12722.vo.msecnd.net/.../integratingtilenotificationsla… · Web viewWindows Phone 7 applications can use Windows Push Notification

For example:

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

Is converted to:

618FD6BA-E587-4C93-9143-D21B2C01E8AD

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. Copy the unencoded list id to the LIST_ID constant value.

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.2.7 comment to define the UpdateNotificationBindings method:

C#

private void UpdateNotificationBindings(){ if (IsNotificationEnabled) { if (Channel != null && !Channel.IsShellTileBound) { Channel.BindToShellTile(); } } else { if (Channel.IsShellToastBound) { Channel.UnbindToShellTile(); }

Page | 18

Page 19: Integrating SharePoint and Windows Phone 7 Tile …az12722.vo.msecnd.net/.../integratingtilenotificationsla… · Web viewWindows Phone 7 applications can use Windows Push Notification

}}

The above code will bind or unbind the device to the tile notifications. When bound the phone will display the new tile as it receives the notification from the Push Notification Service. When the user opts to not receive notifications the channel is not bound to the notification. The phone will not change the application tile.

3. Add the following code under the //TODO: 7.2.8 comment to define the ClearTileCount method.

C#

public void ClearTileCount(){ var svc = new NotificationRegistration.ListNotificationChannelsClient(); svc.ClearRegistrationCountAsync(channelUri.ToString(), Constants.LIST_ID);}

The above code calls the Notification Registration service to clear the count value associated with the specific channel Uri and list id. This methond is called when the application starts. This method calls the registration service’s ClearTileCount. The ClearTileCount will set the count to zero for the channel and list id combination and send a tile notification with a 0 count. Each time the application starts the tile count will return to zero which will display no count on the application tile.

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.2.9 comment to define the MainPage constructor method.

C#

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

Page | 19

Page 20: Integrating SharePoint and Windows Phone 7 Tile …az12722.vo.msecnd.net/.../integratingtilenotificationsla… · Web viewWindows Phone 7 applications can use Windows Push Notification

App.settingsViewModel = new SettingsViewModel();

var settings = SettingsViewModel.Current;

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

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. It then calls the ClearTileCount method. This will clear the tile counter each time the application is opened.

3. Save and close MainPage.Xaml.cs.

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

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

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.

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.

Page | 20

Page 21: Integrating SharePoint and Windows Phone 7 Tile …az12722.vo.msecnd.net/.../integratingtilenotificationsla… · Web viewWindows Phone 7 applications can use Windows Push Notification

\

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 Module 6 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.

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.

Page | 21

Page 22: Integrating SharePoint and Windows Phone 7 Tile …az12722.vo.msecnd.net/.../integratingtilenotificationsla… · Web viewWindows Phone 7 applications can use Windows Push Notification

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.

Exercise 5: Testing the Windows Phone 7 Application

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

Note: This lab requires the firewall be turned off to enable connection 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

Page | 22

Page 23: Integrating SharePoint and Windows Phone 7 Tile …az12722.vo.msecnd.net/.../integratingtilenotificationsla… · Web viewWindows Phone 7 applications can use Windows Push Notification

emulator and restart debugging. Another method to avoid this race condition is to start each project in the solution separately.

Task 1 – Testing the Application’s 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 SharePoint List Item 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 Tile …az12722.vo.msecnd.net/.../integratingtilenotificationsla… · Web viewWindows Phone 7 applications can use Windows Push Notification

Figure 13Application main page with no events displayed

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

Page | 24

Page 25: Integrating SharePoint and Windows Phone 7 Tile …az12722.vo.msecnd.net/.../integratingtilenotificationsla… · Web viewWindows Phone 7 applications can use Windows Push Notification

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 will deploy and activate. The emulator displays items from the Maintenance Training Schedule SharePoint list.

3. Click the Settings icon.

Page | 25

Page 26: Integrating SharePoint and Windows Phone 7 Tile …az12722.vo.msecnd.net/.../integratingtilenotificationsla… · Web viewWindows Phone 7 applications can use Windows Push Notification

Figure 14Settings icon on main page

4. Click Enable Notification checkbox.

Page | 26

Page 27: Integrating SharePoint and Windows Phone 7 Tile …az12722.vo.msecnd.net/.../integratingtilenotificationsla… · Web viewWindows Phone 7 applications can use Windows Push Notification

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 Tile …az12722.vo.msecnd.net/.../integratingtilenotificationsla… · Web viewWindows Phone 7 applications can use Windows Push Notification

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 Tile …az12722.vo.msecnd.net/.../integratingtilenotificationsla… · Web viewWindows Phone 7 applications can use Windows Push Notification

8. Left-click and hold the mouse button down on the Notify + Count 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 Tile …az12722.vo.msecnd.net/.../integratingtilenotificationsla… · Web viewWindows Phone 7 applications can use Windows Push Notification

9. Click pin to start.

Figure 18Application tile pinned to the start page

Page | 30

Page 31: Integrating SharePoint and Windows Phone 7 Tile …az12722.vo.msecnd.net/.../integratingtilenotificationsla… · Web viewWindows Phone 7 applications can use Windows Push Notification

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. The training event data should be in the current month.

Figure 19

Creating a new training event in SharePoint 2010

12. Save the new calender event.

13. Verify the tile count displays 1in the emulator.

Note: The notification may not display immediately.

Page | 31

Page 32: Integrating SharePoint and Windows Phone 7 Tile …az12722.vo.msecnd.net/.../integratingtilenotificationsla… · Web viewWindows Phone 7 applications can use Windows Push Notification

Figure 20Display the toast notification on the start page

14. Click the application tile to open the application.

Page | 32

Page 33: Integrating SharePoint and Windows Phone 7 Tile …az12722.vo.msecnd.net/.../integratingtilenotificationsla… · Web viewWindows Phone 7 applications can use Windows Push Notification

Figure 21Clicking the tile opens the application

15. Click the phone’s back button to verify the tile count is now blank or zero.

Page | 33

Page 34: Integrating SharePoint and Windows Phone 7 Tile …az12722.vo.msecnd.net/.../integratingtilenotificationsla… · Web viewWindows Phone 7 applications can use Windows Push Notification

Figure 22Application tile is now blank

Page | 34

Page 35: Integrating SharePoint and Windows Phone 7 Tile …az12722.vo.msecnd.net/.../integratingtilenotificationsla… · Web viewWindows Phone 7 applications can use Windows Push Notification

Summary

In this hands-on lab, you saw how to use a SharePoint list item event reciever to create tile notifications for registered phone applciations. You learned how to configure a phone application to subscribe to a notification using a WCF service and how bind the device to tile notifications. Finally you have seen how to clear the tile count when the applciation is executed.

Page | 35