My first Windows Phone 7 application: MySite for WP7 - Part 1

17. November 2010 20:48 by marco in Avanade, SharePoint, Silverlight, Software, Windows Phone 7  //  Tags:   //   Comments (0)

A few weeks ago, my employer, Avanade Germany, announced an internal “Windows Phone 7 Contest”. The goal is to create a (business) app for Microsofts new Windows Phone 7 (WP7) system. I just had some ideas and decided to go with “MySite for WP7”. At least because I’m working in the “Portals & Collaboration” Service Line and I really like the new SharePoint 2010 MySite. That, and because the price for the best three apps is an Xbox 360 with Kinect. Winking smile

Overview

If you have no idea, what the SharePoint 2010 MySite is, here is a short introduction: Think about a “little” Facebook (social network) within your company. You can write status messages, see a newsfeed about your colleagues, post comments on the note boards of your colleagues, upload pictures, etc.

I know, that WP7 comes with SharePoint integration, but without a cool client for the MySite. I will try to build one (and hopefully win the Xbox).

Start with WP7

I will not give you an overview what you need to start, because there are a lot of resources to learn WP7 development. I already know .NET, C#, SharePoint and Silverlight and that’s everything you need to start. Download the Development Toolkit (for free) and start up Visual Studio.

First of all I decided to go with the Panorama Template, because it is easy to use and looks really nice. Also it supports my idea of different MySite tasks. The design-time support is great as well. If you click on the panorama page in the XAML code, the designer shows the corresponding page.

image

But before I go into much UI details, we should thought about the backend.

How to connect to SharePoint?

SharepPoint 2010 provides a web services API (WCF and legacy ASMX) to access most of the SharePoint functionality. Therefore I tried to access these services directly from the phone, but that did not work, because of two main points:

So obviously a workaround is required. Here is my idea of a “proxy service”:

image

That means, the WP7 app connects to an SSL secured WCF (silverlight-enabled) proxy service (without authentication) in the cloud. The service then connects to the SharePoint service with the provided credentials. For privacy reasons, a company that do not want to transmit sensitive data over the cloud service can host their own proxy service within their secure environment to make it accessible by their employees.

The proxy service can for example get the current status message from your MySite:

public string GetStatus(AccountCredentials credentials)
{
  var client = GetProfileServiceClient(credentials);

  string fqnUsername = credentials.Domain + "\\" + credentials.Username;
  var data = client.GetUserProfileByName(fqnUsername);

  var statusProp = (from d in data
                    where d.Name == "SPS-StatusNotes"
                    select d).FirstOrDefault();

  return statusProp.Values[0].Value.ToString();
}

I defined a class AccountCredentials which contains username, domain, password and SharePoint MySite URL. This data is entered in the WP7 app by the user. Now the proxy service is called with this data and calls the SharePoint profile service (with the URL provided) to get the current status message.

This approach is not only for communicating with SharePoint, but can also be used with other services which cannot directly be called from the phone.

Alternative to a Proxy Service: UAG

Another fairly new (at least for me) way is the Forefront Unified Access Gateway (UAG). See also this video from TechED. In the video you can see, that Microsoft requires a company to have a UAG in place to use the build-in SharePoint features of WP7. So it seems, that also Microsoft cannot use NTLM on WP7.

WP7 with UAG uses HTTPS for all communications and what is know as basic authentication. One problem why I’m currently not supporting UAG in my App is, because there are no developer resources how to integrate it in your own application. The only info you got from the video is to use signUrl.asp to get the token after authentication. If anyone has more info, please add a comment.

Learn more in part 2 of the series in a few days where I will talk about the User Interface.

Silverlight + Virtual Earth = Genial!

4. April 2009 15:14 by marco in .NET, ASP.NET, Microsoft, Silverlight  //  Tags:   //   Comments (11)

Ich hab mal ausnahmsweise ein bisschen Zeit gehabt um ein paar neue / nicht mehr ganz so neue Technologien anzusehen und auszuprobieren.

Da ich ja nun doch schon seit einiger Zeit meine halbwegs aktuelle Position per Virtual Earth auf woist.mwiedemeyer.de visualisiere und es seit kurzem ein Virtual Earth Silverlight Control gibt, ist es wie geschaffen, um endlich einen ernsthafteren Einstieg in Silverlight 2 zu starten.

Das interactive SDK ist wirklich genial und die Bedienung ist super einfach. Zumindest dann, wenn man bereits ein wenig WPF oder Silverlight Erfahrungen gesammelt hat.

Beispiel:

Man möchte in einer Silverlight Anwendung einfach nur die gesamte Karte darstellen. Dazu reicht es das Map Control zur Seite hinzuzufügen:

<UserControl x:Class="VirtualEarthSilverlightTest.Page"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:m="clr-namespace:Microsoft.VirtualEarth.MapControl;assembly=Microsoft.VirtualEarth.MapControl"
    Width="800" Height="600">
    <Canvas x:Name="LayoutRoot" Background="White">
        <m:Map Name="MyMap"></m:Map>
(...)

Um per code einen Pin (oder jedes andere UIElement, z.B. auch Bilder, Videos, etc.) auf der Karte an einer bestimmten Position anzuzeigen, reicht folgender code:

// Neuen MapLayer hinzufügen um Elemente an Locations anzuzeigen
MapLayer mapLayer = new MapLayer();
MyMap.Children.Add(mapLayer);
// Beliebiges UIElement (Canvas, Border, etc) an der Position latitude, longitude anzeigen
mapLayer.AddChild(anyUIElement, new Location(latitude, longitude));

Ich habe für einen ersten Versuch mal den letzten Urlaub in die Silverlight Karte eingefügt. Hier gibts das ganze nun zu sehen:

http://woist.mwiedemeyer.de/silverlight

UPDATE:

Was ich an der Stelle noch vergessen habe zu erwähnen: Es funktioniert nicht nur im Internet Explorer, sondern auch in Opera (und natürlich auch Firefox…)!