Windows Phone 7 Social Viewer Application Template Released

Hi Guys,

The Social Viewer application template enables you to create mashups from Twitter, Facebook, RSS and Atom feeds with all the plumbing for security, sharing, offline, Trial mode and advertising support built in.

I have tried it out and the Social Viewer template really rocks its makes it extreemly fast and simple to create a mashup WP7 app.  Nick Randolph (Built To Roam) has really done an awesome job on this template.

You can get the full details, and template from Dave Glover in this blog posting. Also note he has mentioned a limited number of Tokens available to Australian devs for free WP7 marketplace registration – quite generous and a surefire way to kickstart your WP7 dev.

If you would like to see an app built with the Social Viewer template try out the Perez Hilton Reader

Kind Regards,

Nick Harris

WP7 Nights at the Round Table – Feb 28

Hi there Windows Phone 7 Developers in Sydney Australia,

Time to get out from infront of the computer and into the bar to talk about windows phone 7 dev and Azure :)

Event:
WP7 Nights at the Round Table – Feb 28th Sydney

Purpose:
Let’s get together for some drinks to trade WP7 Dev stories, demos or seek free advice from other devs to help get your app off the ground and into Marketplace. This event will be informal, around bar tables, so bring along your device or laptop if you wish to show people what you have been up to.

Let us know your coming:

If your on LinkedIn please indicate your attendance here – Windows Phone 7 Developer Dev Drinks Feb 28th or in the comments section below.

Date, Time, Location:

6-8pm
Tues 28th Feb 2010
City Hotel,
Corner of King and Kent St, Sydney CBD.

Hope to see you there,

Nick Harris :)

Two Great Competitions one for Windows Phone 7 and one for Azure

Hi there readers,

There are two great competitions I have come across that I think are well worth mentioning.

  1. The Windows Phone 7 LG App Starter Competition now in the Final Round run by Nick Randolph of Built To Roam.
  2. Windows Azure Marketplace: The DataMarket Contest run by codeproject

Both have great prizes and are well worth checking out.  Why not build a WP7 app that consumes free datasets from the Windows Azure Marketplace DataMarket and enter both ? :)

Kind Regards,

Nick Harris

Windows Phone 7 Navigation is not allowed when the task is not in the foreground

I hit the following issue bouncing around an app that utilised the SmsComposeTask today.  I have simplified the code to the following for demonstration purposes:

private void OnAdClick(object sender, MouseButtonEventArgs e)
{
   SmsComposeTask sms = new SmsComposeTask();
   sms.To = "111";
   sms.Body = "blah";  �
   sms.Show();
}

Issue:

When clicking the button that creates the SMS compose task in quick succession the following occurs.

InvalidOperationException

Navigation is not allowed when the task is not in the foreground. Error: -2147220989

at Microsoft.Phone.Shell.Interop.ShellPageManagerNativeMethods.CheckHResult(Int32 hr)
at Microsoft.Phone.Shell.Interop.ShellPageManager.NavigateToExternalPage(String pageUri, Byte[] args)
at Microsoft.Phone.Tasks.ChooserHelper.Navigate(Uri appUri, ParameterPropertyBag ppb)
at Microsoft.Phone.Tasks.SmsComposeTask.Show()
at Demo.OnAdClick(Object sender, MouseButtonEventArgs e)
at System.Windows.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)
at Microsoft.Xna.Framework.Input.UnsafeNativeMethods.CallWindowProc(IntPtr lpPrevWndFunc, IntPtr hWnd, UInt32 msg, IntPtr wParam, IntPtr lParam)
at Microsoft.Xna.Framework.Input.SafeNativeMethods.CallWindowProc(IntPtr lpPrevWndFunc, IntPtr hWnd, UInt32 msg, IntPtr wParam, IntPtr lParam)
at Microsoft.Xna.Framework.Input.WindowMessageHooker.Hook.WndProc(IntPtr msgWnd, UInt32 msg, IntPtr wParam, IntPtr lParam)

Cause:
The cause is that the first click will launch the SmsComposeTask causing the application to be deactivated i.e sent to the background, with the second click being handled after the deactivated event has occured so its just a matter of cleaning up your click handler.

Kind Regards,
Nick Harris

35ºC, 95ºF bedroom is like a sauna today, difficult to concerntrate, bring on autumn:)

WP7 Nights at the Round Table – Jan 25th

Hi there Windows Phone 7 Developers in Sydney Australia,

Following the success of our xmas Drinks we are going to make this a monthly event :) .  Time to get out from infront of the computer and into the bar to talk about windows phone 7 dev :)

Event:
WP7 Nights at the Round Table – Jan 25th Sydney

Purpose:
Let’s get together for some drinks to trade WP7 Dev stories, demos or seek free advice from other devs to help get your app off the ground and into Marketplace. This event will be informal, around bar tables, so bring along your device or laptop if you wish to show people what you have been up to.

Let us know your coming:

If your on LinkedIn please indicate your attendance here – http://events.linkedin.com/Windows-Phone-7-Dev-Drinks-Jan-25th/pub/536053 or in the comments section below.

Date, Time, Location:

6-8pm
Tues 14th Dec 2010
City Hotel,
Corner of King and Kent St, Sydney CBD.

Hope to see you there,

Nick Harris :)

Check if a Capability is enabled in WMAppManifest on Windows Phone 7

While Microsoft provides the handy Capability Detection Tool to determine what Capabilities are required for your application there are scenarios, one being that you are a provider windows phone 7 library, where you may want to check at runtime what capabilities are present in the WMAppManifest.xml. This post will provide a helper class to check each if each capability is present.

Note: This post leverages the great work done by Nick Randolph to gain access to the WMAppManifest.xml for access to the Application Product ID in his blogpost here

The helper class is as follows:

using Microsoft.Xna.Framework;
using System.Linq;
using System.Xml.Linq;
using System.Collections.Generic;

namespace www.NickHarris.NET
{
    public static class CapabilityHelper
    {
        private const string WMAppManifest = "WMAppManifest.xml";
        private const string ID_CAP_NETWORKING = "ID_CAP_NETWORKING";
        private const string ID_CAP_IDENTITY_DEVICE = "ID_CAP_IDENTITY_DEVICE";
        private const string ID_CAP_IDENTITY_USER = "ID_CAP_IDENTITY_USER";
        private const string ID_CAP_LOCATION = "ID_CAP_LOCATION";
        private const string ID_CAP_SENSORS = "ID_CAP_SENSORS";
        private const string ID_CAP_MICROPHONE = "ID_CAP_MICROPHONE";
        private const string ID_CAP_MEDIALIB = "ID_CAP_MEDIALIB";
        private const string ID_CAP_GAMERSERVICES = "ID_CAP_GAMERSERVICES";
        private const string ID_CAP_PHONEDIALER = "ID_CAP_PHONEDIALER";
        private const string ID_CAP_PUSH_NOTIFICATION = "ID_CAP_PUSH_NOTIFICATION";
        private const string ID_CAP_WEBBROWSERCOMPONENT = "ID_CAP_WEBBROWSERCOMPONENT";
        private const string CAPABILITIES = "Capabilities";
        private const string NAME = "Name";

        static CapabilityHelper()
        {
            using (var strm = TitleContainer.OpenStream(WMAppManifest))
            {
                var xml = XElement.Load(strm);
                var capabilities = xml.Descendants(CAPABILITIES).Elements();

                IsNetworkingCapability = CheckCapability(capabilities, ID_CAP_NETWORKING);
                IsDeviceIdentityCapability = CheckCapability(capabilities, ID_CAP_IDENTITY_DEVICE);
                IsUserIdentityCapability = CheckCapability(capabilities, ID_CAP_IDENTITY_USER);
                IsLocationCapability = CheckCapability(capabilities, ID_CAP_LOCATION);
                IsSensorsCapability = CheckCapability(capabilities, ID_CAP_SENSORS);
                IsMicrophoneCapability = CheckCapability(capabilities, ID_CAP_MICROPHONE);
                IsMediaLibCapability = CheckCapability(capabilities, ID_CAP_MEDIALIB);
                IsGamerServicesCapability = CheckCapability(capabilities, ID_CAP_GAMERSERVICES);
                IsPhoneDialerCapability = CheckCapability(capabilities, ID_CAP_PHONEDIALER);
                IsPushNotificationCapability = CheckCapability(capabilities, ID_CAP_PUSH_NOTIFICATION);
                IsWebBrowserComponentCapability = CheckCapability(capabilities, ID_CAP_WEBBROWSERCOMPONENT);
            }
        }

        public static bool IsNetworkingCapability { get; set; }
        public static bool IsDeviceIdentityCapability { get; set; }
        public static bool IsUserIdentityCapability { get; set; }
        public static bool IsLocationCapability { get; set; }
        public static bool IsSensorsCapability { get; set; }
        public static bool IsMicrophoneCapability { get; set; }
        public static bool IsMediaLibCapability { get; set; }
        public static bool IsGamerServicesCapability { get; set; }
        public static bool IsPhoneDialerCapability { get; set; }
        public static bool IsPushNotificationCapability { get; set; }
        public static bool IsWebBrowserComponentCapability { get; set; }

        private static bool CheckCapability(IEnumerable<XElement> capabilities, string capabilityName)
        {
            var capability = capabilities.FirstOrDefault(n => n.Attribute(NAME).Value.Equals(capabilityName));
            return capability != null;
        }     Â
    }
}

Note: You will need to add a reference to the Microsoft.XNA.Framework.dll for the helper to build. If you are concerned about the warning that shows up when adding a reference to this assembly from within a Silverlight application, rest assured, that it is possible to utilize most, but not all, XNA assemblies in a WP7 Silverlight Application as documented here on msdn. Scroll down to the section Using Classes Across Frameworks to see exclusions.

Usage is then as simple as

   if (!CapabilityHelper.IsUserIdentityCapability)
     //capability not present, do something

Enjoy,
Nick

Finding the Device Model on Windows Phone 7

Previously i detailed how to retrieve the Device Manufacturer and users anonymous id from the device here.  This post details how to capturing the Device Model on Windows Phone 7.

Step 1: Add the ID_CAP_IDENTITY_DEVICE capability to your WMAppManifest.xml

<Capabilities>
   <Capability Name="ID_CAP_IDENTITY_DEVICE"/>
   ...
</Capabilities>

Step 2: Use the DeviceName with DeviceExtendedProperties TryGetValue method as follows:

public static string GetDeviceModel()
{
   string model = null;
   object theModel = null;

   if (Microsoft.Phone.Info.DeviceExtendedProperties.TryGetValue("DeviceName", out theModel))
      model = theModel as string;      

   return model
}

The resulting Model of my device is T8697.

If you are interested in how to access your Applications ProductID, yep the one that can change during marketplace certification please see Nick Randolphs Blog here.

Enjoy,
Nick

Free Event Windows Phone 7 Application Acceleration

Hi All,

Microsoft have invited Nick Randolph our local MVP to run three free Windows Phone 7 application acceleration events.   These are running towards the end of Jan in Sydney, Melbourne and Perth.  I would recommend that you jump over to Nicks Blog to see the agenda and follow through with the registration link as places will be limited and they will be snapped up fast.  Windows Phone 7 Application Acceleration

Enjoy,

Nick Harris

LG App Starter Competition For Windows Phone 7

Hi All,

A cool local Windows Phone 7 Competition with some really great prizes being run by Nick Randolph over at Built To Roam.

Full details are here a mostly copy paste summary follows.

In Short: This competition will run for six weeks. For the first four weeks Nick will be selecting a topic and you’ll have that week to come up with an idea for an app. To enter all you have to do is email Nick your idea before 6pm EST on Sunday. The weekly winner will be announced later that same evening. Each week we’ll be giving a way marketplace tokens and a book. The final two weeks are where you get to actually build your application, submit it to marketplace and email Nick a link to your application. The competition will close at 6pm EST Sunday February 13th and I’ll select the winning entry who will win the LG Optimus 7 device.

Prizes include: 

This competition has just started and round 1 will close on the 9th jan so jump into action and go over to Nick Randolphs blog for full details and get started :)

Ad Platform for Windows Phone 7 with launch in Australia

Hey there good people of the internet, 

A while back I blogged about my Adventure Initiation about  2 to 3 weeks into it there was a minor hiccup in the form of an announcement that an Ad Platform being made available for Windows Phone 7.  In the spirit of finishing something that I gave so much to start I am pleased to announce that I have just had my showcase application for Windows Phone 7 certified. 

Just like any other new business you have to be able to perform all roles.  I guess its time to interview myself :)  

Whats is this showcase application?  

Well it is a preview application for AdGAC my Ad Platform for Windows Phone 7

Hold on I read Adventure Initiation you really left your paid employment to build an Ad Platform, are you crazy?  

You need to be  >= a little crazy to make steps forward.  

Well your interviewing yourself so you can tick the crazy box 

It would be my pleasure :)  

Why AdGAC? 

AdGAC, yep the name was inspired by the great .NET GAC :) .  But moreover it stands for Global Ad Community.  One of the biggest things I found I really really, really really, really did not like about advertising was the content rarely connected with anything I was interested in.  So what I did was integrate a toolbar into my Ad Control to allow me, the end user, the choice to personalise my ad experience thus helping with the prioritisation of content.  Furthermore if I configure it once it will it will travel between applications :) .  I see it as a win win win – win^3 – scenario for end users, advertisers and developers.  End users say what they want and hence will be engaged with the advertisers that want to connect with them and developers still make their hard earned cash. 

So what about a demo? 

I have made it so you can download the AdGAC preview application or you can search for it through marketplace using either “adgac” or “advertise” .  Sure, while the containing application is not beautiful it serves the purpose I built it for, that is, a vehicle to demonstrate the beauty of AdGAC Ad Platform i.e the advertisements and engagement model.  Be sure to use the flick up gesture to get your toolbar to personalise your profile for better matched content – note the effectiveness of this will become more apparent as more Ads are made available.  Here are some screenshots. 

AdGAC preview application

AdGAC preview application

AdGAC preview application

AdGAC preview application

What media types are supported for advertiser campaigns? 

We support text, image and animated gifs of dimensions 480×80 px 

What ways can Advertisers target their campaigns to capture the correct audiences attention? 

Currently we have 5 options available and some more under development.  The five available are: 

  1. by audience Interest
  2. by audience Gender
  3. by audience Age
  4. by Device Manufacturer
  5. by Audience Location

You can find more information here 

In what way can the end users interact with the Advertisers ad content , in other words what click action types / calls to action? 

Currently we have 5 options available and some more under development.  The five available are: 

  1. click to Website – good for directing traffic to your website
  2. click to Call – useful for directing calls into your corporate call centre e.g Charity organisations or Pizza companies
  3. click to SMS compose – useful for SMS promotions
  4. click to Marketplace Detail – useful for driving downloads of a single application or music that is available through Microsoft Marketplace
  5. click to Marketplace Search – useful for driving downloads of all your applications or music that is available through Microsoft Marketplace

You can find more information here 

How do you create campaigns and register applications? 

I  also built an accompanying website used by Developers to manage their applications  and  and Advertisers to manage their advertising campaigns www.AdGAC.com

AdGAC website Advertising for Windows Phone 7

AdGAC website Advertising for Windows Phone 7

Looks like you’ve been pretty busy? 

Surely have :)  

Where to now? 

  • Well I have opened the site for registrations of interest.  I would like to gauge stakeholder interest [ thats you :) ]  and would like to run a closed alpha to gather some feedback.   So if you’re a Developer or Advertiser and would like to be involved in the closed alpha then please do jump on the site www.AdGAC.com and go to the developer or advertiser tab and press Register or go direct through here Register and fill out the form
  • This release is streamlined to get the platform out for some feedback.  I have a whole bunch more ambitious ideas and the passion to implement them so stay tuned :)

Thanks for your time Nick 

No problems 

To my dear tech readers -  you now probably understand why the tech posts this month were fewer then usual I look forward to getting you some more tech when I am back from my holiday early Jan .  Until then, happy Christmas and New Year! 

Kind Regards, 

Nick Harris

How to Reverse Geocode a Location to an Address on Windows Phone 7

I have had a few people recently ask me how to reverse geocode a location to an address on Windows Phone 7.  The answer should be straightfoward but at the moment thats not quite true.

So whats the straightforward answer supposed to be?

Well glad you asked :) It should be to use the CivicAddressResolver class and its ResolveAddressAsync method

Ok so whats the Gotcha?

When you try to resolve an address CivicAddressResolver all you get back is a empty CivicAddress.  Yep the resolve method is not implemented.

So what options do you have?

  1. Wait for the CivicAddressResolver to be implemented. Note: At the time of writing I have not heard of when it will be released.
  2. Use the Bing Maps API to perform your reverse geocode in one of the following ways
    • Add a service reference from your WP7 project to the Bing Maps SOAP API <–  Requires Bing Maps Key to be supplied in code so not ideal as we want to protect this.
    • Call the Bing Maps REST API from within your WP7  project <–  Requires Bing Maps Key to be supplied in code so not ideal as we want to protect this.
    • Either of the above two options but access your  Bing Maps Key on a service and request it over SSL for device use – ensures XAP  does not contain key but still returning it to the device over the wire
    • Proxy the call to the Bing Maps REST API in your own WCF Service so your Bing Maps Key never hits the device <– ideal method until CivicAddressResolver is implemented.

If you would prefer grab the code then reading through here it is – You can download the code from this linked page

The remainder of this post will detail how to go about implementing the last option above i.e Proxy the call to your own service so that the Key is not available on the WP7 device.

Creating the WCF Service

  1. In Visual Studio 2010 File –> Add New Project –> Select WCF Service Application
  2. Name the Project “ReverseGeocodeService”
  3. On ReverseGeocodeService Right Click –> Add Reference –> Select System.Configuration (we will use this for retrieving your Bing Maps key from configuration).
  4. Set the project to use the local IIS webserver as the host.  On ReverGeocodeService Right Click –> Properties –> Web –> select Use Local IIS Web server and provide a project URL of http://localhost/ReverseGeocodeService
  5. Create the following Folder structure and add the following files within your service
  6. Create your BingLocationResponse class as follows:
  7. Note this class details the how to serialize and deserialize a response from the Bing Maps Rest API and we will use it deserialize the JSON response from the Bing Maps REST API and then also use it both to return a response to the WP7 client

    using System.Runtime.Serialization;
    
    namespace ReverseGeocodeService.Contracts.Data
    {
        [DataContract]
        public class BingLocationResponse
        {
            [DataMember]
            public string authenticationResultCode { get; set; }
            [DataMember]
            public string brandLogoUri { get; set; }
            [DataMember]
            public string copyright { get; set; }
    
            [DataMember]
            public ResourceSet[] resourceSets { get; set; }
    
            [DataMember]
            public string statusCode { get; set; }
            [DataMember]
            public string statusDescription { get; set; }
            [DataMember]
            public string traceId { get; set; }
    
            [DataContract]
            public class ResourceSet
            {
                [DataMember]
                public int estimatedTotal { get; set; }
    
                [DataMember]
                public Resource[] resources { get; set; }
    
                [DataContract(Namespace = "http://schemas.microsoft.com/search/local/ws/rest/v1", Name = "Location")]
                public class Resource
                {
                    [DataMember]
                    public string __type { get; set; }
    
                    [DataMember]
                    public double[] bbox { get; set; }
    
                    [DataMember]
                    public string name { get; set; }
    
                    [DataMember]
                    public Point point { get; set; }
    
                    [DataContract]
                    public class Point
                    {
                        [DataMember]
                        public string type { get; set; }
    
                        [DataMember]
                        public string[] coordinates { get; set; }
                    }
    
                    [DataMember]
                    public Address address { get; set; }
    
                    [DataContract]
                    public class Address
                    {
                        [DataMember]
                        public string addressLine { get; set; }
                        [DataMember]
                        public string adminDistrict { get; set; }
                        [DataMember]
                        public string adminDistrict2 { get; set; }
                        [DataMember]
                        public string countryRegion { get; set; }
                        [DataMember]
                        public string formattedAddress { get; set; }
                        [DataMember]
                        public string locality { get; set; }
                        [DataMember]
                        public string postalCode { get; set; }
                    }
    
                    [DataMember]
                    public string confidence { get; set; }
    
                    [DataMember]
                    public string entityType { get; set; }
                }
            }
        }
    }
  8. Next Define the Interface for your WCF service IGeocodeService.cs and your Geocode Provider that will call out to Bing Maps
  9. IGeocodeService.cs:

    using System.ServiceModel;
    using ReverseGeocodeService.Contracts.Data;
    
    namespace ReverseGeocodeService.Contracts
    {
        [ServiceContract]
        public interface IGeocodeService
        {
            [OperationContract]
            string GetAddress(double latitude, double longitude);
    
            [OperationContract]
            BingLocationResponse GetFullAddress(double latitude, double longitude);
        }
    }
    

    IGeocodeProvider.cs:

    using System;
    using ReverseGeocodeService.Contracts.Data;
    namespace ReverseGeocodeService.Contracts
    {
        public interface IGeocodeProvider
        {
            BingLocationResponse ReverseGeocode(double latitude, double longitude);
        }
    }
  10. Implement your GeocodeProvider.cs
  11. This class will call out to the Bing Maps REST API return its deserialized its response. If you want to see what other options Bing Maps REST API provides you should use this as your starting point and more specifically for the Locations by Point we are using in this example see this

    using System;
    using System.Diagnostics;
    using System.Net;
    using System.Runtime.Serialization.Json;
    using ReverseGeocodeService.Contracts;
    using ReverseGeocodeService.Contracts.Data;
    
    namespace ReverseGeocodeService.Providers
    {
        public class GeocodeProvider : IGeocodeProvider
        {
            private readonly string _bingMapsKey;
            private string _bingMapsRESTUri = "https://dev.virtualearth.net/REST/v1/Locations/{0}?key={1}";
            public GeocodeProvider(string bingMapsKey)
            {
                _bingMapsKey = bingMapsKey;
            }        
    
            public BingLocationResponse ReverseGeocode(double latitude, double longitude)
            {
                BingLocationResponse result = null;
                string formattedLocation = string.Format("{0},{1}", latitude, longitude); //bing maps requires Lat,Long
                var request = HttpWebRequest.Create(string.Format(_bingMapsRESTUri, formattedLocation, _bingMapsKey)) as HttpWebRequest;
                try
                {
                    using (var response = request.GetResponse() as HttpWebResponse)
                    {
                        result = GetResult(response);
                    }
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(ex.ToString());
                }
    
                return result;
            }
    
            private BingLocationResponse GetResult(HttpWebResponse response)
            {
                BingLocationResponse location = null;
                if (response != null && response.StatusCode == HttpStatusCode.OK)
                {
                    //Deserialize the response and provide the address to the callback action
                    using (var stream = response.GetResponseStream())
                    {
                        DataContractJsonSerializer serialiser = new DataContractJsonSerializer(typeof(BingLocationResponse));
                        location = serialiser.ReadObject(stream) as BingLocationResponse;
                    }
                }
    
                return location;
            }
        }
    }
  12. Finally implement your WCF Service GecodeService.svc.cs as follows
  13. Note that the BingKey is externalised into your config files appSettings, for the example to work you will need to supply your key to the config file.

    using System.Configuration;
    using System.Linq;
    using System.ServiceModel;
    using ReverseGeocodeService.Contracts;
    using ReverseGeocodeService.Contracts.Data;
    using ReverseGeocodeService.Providers;
    
    namespace ReverseGeocodeService
    {
        [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
        public class GeocodeService : IGeocodeService
        {
            //TODO: set your bingkey in config appsetting named BingKey
            private static IGeocodeProvider _geocodeProvider = new GeocodeProvider(ConfigurationManager.AppSettings["BingKey"]);
    
            public string GetAddress(double latitude, double longitude)
            {
                string formattedAddress = null;
                var geocodeResult = _geocodeProvider.ReverseGeocode(latitude, longitude);
                if (geocodeResult != null
                                && geocodeResult.resourceSets != null
                                && geocodeResult.resourceSets.Any()
                                && geocodeResult.resourceSets.First().resources != null
                                && geocodeResult.resourceSets.First().resources.Any())
                {
                    formattedAddress = geocodeResult.resourceSets.First().resources.First().address.formattedAddress;
                }
    
                return formattedAddress;
            }
    
            public BingLocationResponse GetFullAddress(double latitude, double longitude)
            {
                return _geocodeProvider.ReverseGeocode(latitude, longitude);
            }
        }
    }
  14. Add the appSettings section to your Web.config and supply your Bing Maps API Key
  15. <configuration>
     <appSettings>
        <add key="BingKey" value="Bing Maps Key Here"/>
      </appSettings>
      ...
    </configuration>

    Note: you should encrypt this Key using whatever standard practices you use.

Creating the Windows Phone 7 Client

Note: this is not an example of how to create an MVVM implementation on WP7  i.e we are focusing on how to reverse geocode a location to an address through the use of a proxy service  to protect your Bing Maps Key as such in this post the client code is kept straightforward to demonstrate usage.

  1. Add a Windows Phone 7 project File --> New Project --> Silverlight for Windows Phone --> Windows Phone Application
  2. Name the project ReverseGeocode
  3. On the project Right Click --> Add Service Reference --> Press Discover.
  4. You should see a window as in the following image.  Provide the Namespace ReverseGeocodeClient and Press OK
  5. Note: If this step is generating an Empty ServiceReferences.ClientConfig then delete the Service References and Service References.ClientConfig. Close all instances of Visual Studio. Open Visual Studio and try to add it again - it worked for me :) . If this still doesn't work then you will need to use SlSvcUtil.exe located in your Program Files (Program Files (x86)) for 64bit machines as follows:
    C:\Program Files (x86)\Microsoft SDKs\Windows Phone\v7.0\Tools\SlSvcUtil.exe" http://localhost/ReverseGeocodeService/GeocodeService.svc?wsdl
    Take the two files from the output and include them in your project and continue.

  6. Right click on the generated ServiceReferences.ClientConfig and set its Build Action to Content and Copy to Output Directory to Copy if newer
  7. Add a couple of buttons to perform calls out to the service in your MainPage.xaml and a TextBlock to display the result
  8. <phone:PhoneApplicationPage
        x:Class="ReverseGeocode.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
        xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
        FontFamily="{StaticResource PhoneFontFamilyNormal}"
        FontSize="{StaticResource PhoneFontSizeNormal}"
        Foreground="{StaticResource PhoneForegroundBrush}"
        SupportedOrientations="Portrait" Orientation="Portrait"
        shell:SystemTray.IsVisible="True" Loaded="PhoneApplicationPage_Loaded">
    
        <!--LayoutRoot is the root grid where all page content is placed-->
        <Grid x:Name="LayoutRoot" Background="Transparent">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
    
            <!--TitlePanel contains the name of the application and page title-->
            <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
                <TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
                <TextBlock x:Name="PageTitle" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
            </StackPanel>
    
            <!--ContentPanel - place additional content here-->
            <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
                <Button Click="btnGetAddress_Click" Content="Get Address" Height="72" HorizontalAlignment="Left" Margin="6,6,0,0" Name="button1" VerticalAlignment="Top" Width="270" />
                <TextBlock x:Name="txtAddress" Height="203" HorizontalAlignment="Left" Margin="12,163,0,0" Text="Address goes here" VerticalAlignment="Top" Width="425" />
                <Button Content="Get Full Response" Height="72" HorizontalAlignment="Left" Margin="5,72,0,0" Name="button2" VerticalAlignment="Top" Width="270" Click="btnGetFullResponse_Click" />
            </Grid>
        </Grid>
    
    </phone:PhoneApplicationPage>
  9. Update your codebehind, MainPage.xaml.cs to call out to your new Reverse geocoding service when buttons are clicked
  10. using System;
    using System.Linq;
    using System.Windows;
    using Microsoft.Phone.Controls;
    using ReverseGeocode.ReverseGeocodeClient;
    
    namespace ReverseGeocode
    {
        public partial class MainPage : PhoneApplicationPage
        {
            private GeocodeServiceClient _client;
            private const string NO_RESULT_FOUND = "No Result Found";
            // Constructor
            public MainPage()
            {
                InitializeComponent();
            }
    
            private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
            {
               _client = new GeocodeServiceClient();
               _client.GetAddressCompleted += new EventHandler(client_GetAddressCompleted);
               _client.GetFullAddressCompleted += new EventHandler(_client_GetFullAddressCompleted);
            }
    
            private void btnGetAddress_Click(object sender, RoutedEventArgs e)
            {
                _client.GetAddressAsync(-33.796526, 151.138267);
            }        
    
            private void btnGetFullResponse_Click(object sender, RoutedEventArgs e)
            {
                _client.GetFullAddressAsync(-33.796526, 151.138267);
            }
    
            void client_GetAddressCompleted(object sender, GetAddressCompletedEventArgs e)
            {
                txtAddress.Text = e.Result ?? NO_RESULT_FOUND;
            }
    
            void _client_GetFullAddressCompleted(object sender, GetFullAddressCompletedEventArgs e)
            {
                string result = NO_RESULT_FOUND;
                if (e.Result != null
                                && e.Result.resourceSets != null
                                && e.Result.resourceSets.Any()
                                && e.Result.resourceSets.First().resources != null
                                && e.Result.resourceSets.First().resources.Any())
                {
                    var x = e.Result.resourceSets.First().resources.First();
                    result = string.Format ("Address:\n{0}\nConfidence:\n{1}\n", x.address.formattedAddress, x.confidence);
                }
    
                txtAddress.Text = result;
            }
        }
    }

    Note: I have not done it in this example however when you are finished with your _client you should always call _client.CloseAsync();

Summary:
And there you have it - in the absence of CivicAddressResolver this provides an implementation to reverse geocode a latitude and longitude into an Address on Windows Phone 7 without the need for your Bing Maps key to either be stored in the XAP or retrieved from a service by keeping your key within the context of your WCF proxy service.

You can download the code from this linked page - note you will have to add your Bing Maps Key to the web.config for it to work and also create the virtual directory on local host as detailed in the WCF service steps.

I hope this has helped you save some time :)

Enjoy,
Nick

Lets have Windows Phone 7 Dev XMass Drinks in Sydney

Hi there Windows Phone 7 Developers in Sydney Australia,

I thought it would be cool to meet each other in person over some informal XMass drinks. So without any further delay, here are the details:

Event:
WP7Dev XMass Drinks meet and greet

Please indicate your attendance here – http://events.linkedin.com/Windows-Phone-7-Developer-XMass-Drinks/pub/496913

Purpose:
Let’s get together for some XMass Drinks and/or dinner to trade some WP7 Dev stories and demos. Event will be informal, i.e around bar tables, so bring along your device or laptop if you wish to show people what you have been up to.

Date, Time, Location:

6-8pm
Tues 14th Dec 2010
City Hotel,
Corner of King and Kent St, Sydney CBD.

Hope to see you there,

Nick Harris :)

Using TouchPanel for Gestures in Windows Phone 7

The Silverlight for Windows Phone Toolkit has some excellent controls, one of which is the GestureListener which makes implementing gesture support a very straightforward task.   However, as happens from time to time you’re hit with a scenario where you’re unable to depend on any third party content and as such I needed to add my own basic handling for gestures.  This is how you do it:

1. Add reference to Microsoft.Xna.Framework.Input.Touch.dll – Note: you will get a warning here that you can ignore for now.

2. In code behind  the gestures you want to listen for

The Gesture types you can enable are as follows Tap, DoubleTap, Hold, HorizontalDrag, VerticalDrag, FreeDrag, Pinch, Flick, DragComplete, PinchComplete

In my case I only want to deal with Flick, Hold and Tap therefore add the following:
TouchPanel.EnabledGestures = GestureType.Flick | GestureType.Hold | GestureType.Tap;

3. Limiting the scope for the gestures.

I want the gestures to be captured only when performed in a given for a StackPanel.  To do this I handle the ManipulationCompleted event on the StackPanel as follows:

<StackPanel ManipulationCompleted="StackPanel_ManipulationCompleted">

...

</StackPanel>

Note: if you wanted the gesture available to the content of the whole page then you would handle the ManipulationCompleted event of the PhoneApplicationPage.

4. Add handling code as follows


private void StackPanel_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
{
   //Check if touch Gesture is available
   if (TouchPanel.IsGestureAvailable)
   {
      // Read the gesture so that you can handle the gesture type
      GestureSample gesture = TouchPanel.ReadGesture();
      switch (gesture.GestureType)
     {
         case GestureType.Flick:
         case GestureType.Hold:
            ToggleToolbarVisibility();
         break;
         case GestureType.Tap:
            Navigate();
         break;
         default:
            //do something
         break;
      }
   }
}

Enjoy,

Nick

Tips for a Fast Windows Phone 7 Developer Phone Registration

Steps to register a Windows Phone 7 device:
  1. Open Zune on your PC
  2. Turn on your WP7 device and unlock the screen
  3. Connect your device and ensure Zune can see your WP7 device
  4. Open the Windows Phone Developer Registration Application (All Programs –> Windows Phone Developer Tools –> Windows Phone Developer Registration).  This tool should display a status showing that the phone is ready.
  5. Enter your Windows Live ID and password then click Register
  6. If all goes well you should see a message. Registration successful.

At this stage it should have all worked.  If it didn’t you should read on.

Tips for ensuring successful registration of the phone – Step 6 above:

  1. Prepare for GeoTrust verification early. Get a phone  Phone Bill that is <= 6 months old,  scanned  that shows your name  or Company Name (same as applying in app hub) and your your phone number.  If you don’t have this you will have to get a template letter they provide signed and witnessed by someone like a JP.
  2. Ensure you have a phone plugged in for GeoTrust to call you on :)
  3. You need to have signed up on App Hub.
  4. You need to have gone through the GeoTrust verification process – phone call and bill provided.

So what next, you may find that GeoTrust have called and verified you but the Windows Phone Developer Registration Application still fails. In my case it was with the following error:

Status: Marketplace registration incomplete. Please return to the developer portal for more information. (ErrorCode:0×80043009)

Solution: So it turns out this means that your GeoTrust identity verification is incomplete.  But thats weird right, they just verified you.  You can double check the by logging into your App Hub and going to My Dashboard –> Windows Phone.

If the Publisher identity verification  is not complete you will not see a tick as per below and in its place you will see an Arrow:

So what do you do, particularly in Australia:

The FAQ states to to contact GeoTrust support chat: https://www.geotrust.com/support/chat/order-processing.html

After trying this a number of times I was never able to get through to the chat.  It was always asking which state in the US you are from and also for the order ID.  After entering Aust over a couple of days and having to send an email with a description of the problem I had not heard back.

So I decided to move to Washington for about 30 minutes :) , and within seconds I was in a chat.  Apparently the issue was they needed another email address that included my name.  After giving them the extra detail they then said it should be processed by Microsoft within 24hours.  ~3hours later the job was done – fast, Azure worker roles?.   You can check within App Hub by verifying the Publisher identity verification is correct,  You will see a tick as per the following

At this point you should then run through the steps at the top of this article to register your phone.  If that too is successful it the Status in the Windows Phone Developer Registration Application will indicate so.

Hope these tips help save you a couple of days :)

Nick

How to Create a Custom Pushpin Control Template in Expression Blend for Windows Phone 7 Bing Maps

You may find yourself building a Windows Phone 7 application with the Bing Maps control. When you add the default Pushpin to your map you map you may find that you want a little more, perhaps to establish your brand a bit more or to make the pushpin fit in with the rest of your application. This post details the basics of how to create a Custom Pushpin Control Template in Expression Blend.

Steps are as follows:

  1. Open Visual Studio – yes we are going to start from here :)
  2. File –> New –> Project …
  3. Select Silverlight for Windows Phone then Windows Phone Application.  Name the project CustomPushpin and click Ok.
  4. Right click on your project in Visual Studio and select Open in Expression Blend…
  5. In Blend select the projects tab, Right Click on References and add a Reference to C:\Program Files (x86)\Microsoft SDKs\Windows Phone\v7.0\Libraries\Silverlight\Microsoft.Phone.Controls.Maps.dll
  6. Select the Assets Tab and type in Map
  7. Drag the Map control onto the page then right click and select Auto Size –> Fill
  8. Set the mode on the map to Aerial
  9. In the Assets Tab drag on a MapItemsControl
  10. In the Assets Tab type inPushpin and Drag two Pushpins onto the Map
  11. In the Properties tab change the color of one Pushpins to red so that it stands out
  12. Select the remaining Pushpin and right click –> select Edit Template –> press Edit a Copy…
  13. In the Create ControlTemplate Resource specify the Name (key) for the resource to be CustomPushpinControlTemplate and press Ok
  14. Crate your custom Pushpin using the blend tools
  15. End Result – yes I am not much of a graphic designer ;)
  16. Note that now when you add new pushpins all you can re-use this template. This can be done through the XAML or on the properties tab in the Miscellaneous group.  Select Template, Local Resource, CustomPushpinTemplate.
  17. Save your blend project and return to Visual studio.  It will prompt you to reload the project.  Click Reload.

Note: rather then having gradient fills, Ellipse etc as your custom template, you could simply add an image to your project and set the image control to that resource in your custom template. Just ensure your build action on the image is Content.

From a developer perspective Blend did make it quite fast to create a custom Pushpin with some nice gradients.    From here i could take the output and start building in my MVVM implementation to add my Pushpins from a service feed or through capturing user clicks.

You can download the output from the blend session here: Full Visual Studio Solution

Enjoy,

Nick

MarketplaceReviewTask

A question come up on the App Hub forums a few days back and I thought it would be an interesting one to talk through.  The question was along the following lines:

  1. Is there a way to capture reviews of your application?
  2. What is the general user a opinion about ‘Nag’ screens that pop up asking for a product review as seen in some iPhone Applications
  3. What is an acceptable method when asking for Reviews i.e ‘Nag’ screen verse passive link

To answer these questions we need to look at the MarketplaceReviewTask and Windows Phone 7 Application Certification Requirements. - Note you can always find the latest version of the application certification requirements over on App Hub 

  1. Is there a way to capture reviews of your application?
  2. First I some people may wonder why would you want a review, well – allowing users to review your application will help (well depends on the review :) ) you stand out in what will eventually become a very competitive marketplace.  Good reviews will ultimately help to drive downloads of your application.   To provide the user the ability to review you application the Microsoft.Phone.Tasks namespace provides the  MarketplaceReviewTask specifically for this reason.  Now before we jump to the code for implementing this I think it is first important to talk through the remainder of the questions.

  3. What is the general user a opinion about ‘Nag’ screens that pop up asking for a product review as seen in some iPhone Applications?
  4.  I for one am definitely not keen on nag screens of any description, for the simple reason that they can be annoying and can turn someone from enjoying their in app experience and by extension, for many non tech users, their windows phone 7 experience.

  5. What is an acceptable method when asking for Reviews i.e ‘Nag’ screen verse passive link
  6. The general rule of thumb here is that the Windows Phone 7 Application Certification Requirements detail whats ok and whats not ok.  But like any document its difficult to put in every single thing upfront and as a result documents evolve over time.  Currently there is no mention of MarketplaceReviewTask nag screens.  However as a developer I would urge you not to take such a path.  On one hand you may get your reviews through brute force nagging but on the otherhand you may just frustrate your users until they uninstalling the app (I would) or writing a bad review.  In my opinion as devs we need to keep in mind that applications play a big role in the success of WP7 adoption.  If we can have happy rather then frustrated users then we are in a good position to continue moving forward.   Thats why i like the suggestion in the forum of using a passive Submit a Review link in the application and  here is how you would implement it in code.

To implement you use the Microsoft.Phone.Tasks; namesplace and the MarketplaceReviewTask.

In your page add the following XAML:

<HyperlinkButton Content="Submit A Review" Height="30" HorizontalAlignment="Left" Margin="225,665,0,0" Name="btnSubmitReview" VerticalAlignment="Top" Width="200" Click="btnSubmitReview_Click" />

In the code code behind of your page add:

using Microsoft.Phone.Tasks;

and add code to your handler as follows:

private void btnSubmitReview_Click(object sender, RoutedEventArgs e)
{
     MarketplaceReviewTask review = new MarketplaceReviewTask();
     review.Show();
}

The end result is as follows:

MarketplaceReviewTask

MarketplaceReviewTask

Note:
1. The MarketplaceReviewTask will cause your application to be tombstoned so you will need to add handing for that.
2. Running this in the emulator will display a warning/error dialog.

Enjoy,
Nick :)

Windows Phone 7 Dev News

What an exciting time to be a developer. I have to say attending PDC shed some light on some seriously cool leaps forward in the Microsoft technology stack IE9, HTML5, Azure and you guessed it Windows Phone 7. This post is a update on the recent Windows Phone 7 related dev tool announcements:

  1. Updated OData Client Library for Windows Phone 7  
  2. Windows Phone 7 analysis tools – not yet released but would love to get my hands on it eary
  3. At PDC an upcoming performance analysis tool to run an instrumented version of your app on devices to provides profiler data in Visual Studio was demonstrated. In the demo the profiling performed gave data on CPU utilisation, frames per second and storyboard animations.

  4. Application Analytics and Code Obfuscation for Windows Phone 7 and Windows Phone Marketplace
  5. Free analytics and code obfuscation for WP7. Well worthwhile using to analyse how your users use your apps and protect your IP through obfuscation

  6. Sync Framework v4 Oct 2010 CTP bits
  7. Check out the cool WP7 client sample to synchronize your data from and Azure cloud service. This is a really great enabler for offline capable smart client applications

  8. Silverlight for Windows Phone 7 toolkit November
  9. New Components; AutoCompleteBox, ListPicker, LongListSelector, Page Transitions.
    Existing Components; GestureService/GestureListener, ContextMenu, DatePicker, TimePicker, ToggleSwitch, WrapPanel

  10. October 2010 update for WP7 Dev tools
  11. Includes: A new Windows Phone Capability Detection Tool, Windows Phone Connect Tool – connect your PC and phone without needing Zune running and Updated Bing Maps Silverlight Control – performance improvements to guesture controls

Enjoy,
Nick

Windows Phone 7 WebBrowser control Script Notify

Recently I was talking to someone who was just starting to look at implementing Push Notifications in one of their Windows Phone 7 applications – specifically for the Raw Notification functionality.

After a little bit of probing i found that the desired sequence that was intended to be used was along the following lines

  1. Application is used to customise an order
  2. WebBrowser Control used for taking payment
  3. Successful Payment must redirect to a succes page in the WebBrowser control
  4. Server to send Push notification – Raw so the application could acknowledge successful payment and transition the UI away from the WebBrowser control.

Now Push Notifications are indeed cool, I played around with them in the April CTP and created a Push Notification API and another post on how to receive notifications on the WP7 client (update for the current RTM in progress – more on this later). This took some time as it was early days for WP7 and there was not much documentation to create the first cut of the API. The main point to note here is it took time and adds an extra layer of complexity to your solution.

Now like any other tech decision as much as the uber cool, funky, and shiney factor seems to influence people its also important to consider – fit for use.
And as a result the scenario above was updated to use ScriptNotify of the WebBrowser control to remove the overhead of implementing Push Notifications – Raw. The updated sequence now becomes:

  1. Application is used to customise an order
  2. WebBrowser Control used for taking payment
  3. Successful Payment must redirect to a succes page in the WebBrowser control
  4. Success page uses javascript to perform a Notify to the WebBrowser control to transition the UI.

The following has been simplified to demonstrate the key code that required to do this:

  1. On the WebBrowser control set IsScriptEnabled to true and provide a handler for ScriptNotify
  2. <phone:WebBrowser IsScriptEnabled="True"  ScriptNotify="webBrowser_ScriptNotify" HorizontalAlignment="Left" Name="webBrowser"  VerticalAlignment="Top"/>
  3. handle the notify event in the code behind
  4.         private void webBrowser_ScriptNotify(object sender, NotifyEventArgs e)
            {
                int orderId = 0;
                int.TryParse(e.Value, out orderId);
    
                if(orderId > 0)
                    //TODO: transition
            }
  5. In the HTML of the success page that is redirected to in step 3 perform a JS notify as follows:
              window.external.notify("123")

Enjoy,

Nick

Windows Phone 7 HttpWebRequest returns same response from Cache

I hit an problem doing some dev on Windows Phone 7 several weeks back and have since helped a couple people out in the old windows phone 7 forum and LinkedIn Windows Phone 7 user group with the same thing.  This issue, is in fact, not an issue – it is more of a lack of knowledge that the HttpWebRequest and WebClient cache responses for your web request.  Let me tell you that client side caching is a good thing that will save you bandwidth and also speed up the percieved user experience when requesting the same resource.  So probably best to get straight to where problems can be faced. 

If you are performing a HttpWebRequest to a uri like so:

string someUri = "http://someservice/service/GetContent/userid/";
HttpWebRequest request = HttpWebRequest.CreateHttp(someUri);           Â
request.Accept = "application/json"; 

request.BeginGetResponse(OnGetSomeontentCallback, new GetSomeContentState(request, onResultAction));Â

Now lets pretend your service implementation has some smarts around what the user has seen historicaly and returns a different image each time you request the same uri.  You will find on your second call to the service that the same image is displayed in your app as the first call and then you might scratch your head *scratch*, check your service logic – all looks ok, set a breakpoint in your service and bang – the breakpoint is not being hit in the service on the second call and suddently is becomes clear the HttpWebRequest (and WebClient) for that matter will cache the response for that uri. 

So your faced with the following question – Should I change my service interface or change/remove the client side caching for this service operation?.   Well the answer is application specific and will fall into two categories:

1. Your client application knows what resource should be next

  • In this case you should alter your service interface to accept the Id of the item this way the result will be cached only for each specific item.

2. Your client has no idea what should be next as the server figures it out 

  • In this scenario i have identified 3 options – initialy i though you would be able to change the cache to expire or not cache on the HttpWebRequest instance but this is not in fact possible so you have to look at the uri and/or serverside.   Here are 3 options: 

Option 1: Add a random Query String to the end of your URI (think Guid.NewGuid()) this will avoid caching on the client as the Query String will be different each time

Option 2. Specify no cache in the OutgoingResponse header within your WCF service operation:


public ResultABC GetContent(string abc)
{
...
WebOperationContext.Current.OutgoingResponse.Headers.Add("Cache-Control", "no-cache");  //This line
...
return ...;
}

Option 3. markup your service operation with the AspNetCacheProfile attribute:

[AspNetCacheProfile("GetContent")]
public ResultABC GetContent(string abc)
{
...
...
return ...;
}

update your web.config


<system.web>
<caching>
     <outputCache enableOutputCache="true" />
     <outputCacheSettings>Â
        <outputCacheProfiles >Â
            <add name="GetContent" duration="0" noStore="true" location="Client" varyByParam="" enabled="true"/>Â
        </outputCacheProfiles>Â
    </outputCacheSettings>
</caching>
...
</system.web>

What did I choose:
Well all methods work to avoid the particular scenario given.  But in my case, the client application never knows what is next so I was forced to stop the client side cachingso the one I opted for was Option 3 as externalising this configuration means you can change at any later time without needing to rebuild and deploy your service.  

 If my client did know what the user was requesting then I would have gone for passing the ID in the uri to ensure that it is unique per each resource and that each resource would be cached on its unique uri.  Note here it is important for the ID to be passed on the URI it appears the URI forms the key for the cache i did see one example where the user was passing the ID in the Header collection e.g wc.Header["ID"] = id; and this was exhibiting the same problem.  Moving the ID to the URI solves the problem.

Hope this has been helpful,

Nick

 

I Won a Windows Phone 7 at PDC Replay

Hi there readers,

Last night i was at The SAUG  I was thinking about how far away the dream of owning one of these Windows Phone 7 devices would be especially since i had resigned from my job almost three months ago, sacraficing my salary to embark on a dream Development Adventure  that utilisies some of the techonologies I have been blogging about over the past few months – Azure, Windows Phone 7 and ASP .NET MVC 2 + 3(beta)

This is particularly great news and i am still quite excited so here it is  - I am now the happy new owner of a Windows Phone 7 – its just not delivered yet and in my excitement I forgot to ask which Model it was going to be. I haven’t had a chance to play with the hardware although have heard good things - I am really hoping it will be a HTC or Samsung model – but I guess I will see what comes :) .

A big thanks to Microsoft and their PDC replay event this morning at 9am and a very special thanks to Andrew Coates who asked the question about Windows Phone 7 that managed to win me this device :) .  I would list the Q&A but there is another replay session occuring now so dont want to spoil it of anyone.

Nick :) :) :)

Windows Phone Developer Tools October 2010 Update

The Windows Phone Developer Tools October 2010 Update includes:
  • Windows Phone Capability Detection Tool – Detects the phone capabilities used by your application. When you submit your application to Windows Phone Marketplace , Microsoft performs a code analysis to detect the phone capabilities required by your application and then replaces the list of capabilities in the application manifest with the result of this detection process. This tool performs the same detection process and allows you to test your application using the same list of phone capabilities generated during the certification process. For more information, see How to: Use the Capability Detection Tool.
  • Windows Phone Connect Tool – Allows you to connect your phone to a PC when Zune® software is not running and debug applications that use media APIs. For more information, see How to: Use the Connect Tool.
  •  Updated Bing Maps Silverlight Control – Includes improvements to gesture performance when using Bingâ„¢ Maps Silverlight® Control.

Download Here

Windows Phone 7 – How to find the device unique id windows live anonymous Id and manufacturer

This post details how to use DeviceExtendedProperties and UserExtendedProperties classes from the Microsoft.Phone.Info namespace to find a WP7 device manufacturer, device unique Id and users Anonymous Windows Live ID as follows:

To be able to obtain the Device Unique ID and Windows Live Anonymous ID you must first add the capabilities to do this to your WMAppManifest.xml file within your WP7 project as follows:

    <Capabilities>
      ...
      <Capability Name="ID_CAP_IDENTITY_DEVICE"/>
      <Capability Name="ID_CAP_IDENTITY_USER"/>
      ...
    </Capabilities>

One important point to note is that you should only really use the device unique id and anonymous windows live Id in your application if really requires it. The reasoning on msdn is as follows:

DeviceExtendedProperties requires the device identity capability. If your application uses this class, the user will be alerted that the application requires access to the device identity when viewing your application on Windows Phone Marketplace. For this reason, it is recommended that you use this class only if your application requires it.

Note: In the example below the manufacturer is returned from GetManufacturer without needing to list the device identity capability within the WMAppManifest but if you tried to get the device Id onr anonymous Id without the capability it will throw an UnauthorizedAccessException.

The following code example demonstrates how to retrieve the Device Manufacturer, Device Unique ID and Windows Live Anonymous ID

using Microsoft.Phone.Info;
namespace NickHarris.Net
{
    public static class ExtendedPropertyHelper
    {
        private static readonly int ANIDLength = 32;
        private static readonly int ANIDOffset = 2;
        public static string GetManufacturer()
        {
            string result = string.Empty;
            object manufacturer;
            if (DeviceExtendedProperties.TryGetValue("DeviceManufacturer", out manufacturer))
                result = manufacturer.ToString();

            return result;
        }

        //Note: to get a result requires ID_CAP_IDENTITY_DEVICE
        // to be added to the capabilities of the WMAppManifest
        // this will then warn users in marketplace
        public static byte[] GetDeviceUniqueID()
        {
            byte[] result = null;
            object uniqueId;
            if (DeviceExtendedProperties.TryGetValue("DeviceUniqueId", out uniqueId))
                result = (byte[])uniqueId;

            return result;
        }

        // NOTE: to get a result requires ID_CAP_IDENTITY_USER
        //  to be added to the capabilities of the WMAppManifest
        // this will then warn users in marketplace
        public static string GetWindowsLiveAnonymousID()
        {
            string result = string.Empty;
            object anid;
            if (UserExtendedProperties.TryGetValue("ANID", out anid))
            {
                if (anid != null && anid.ToString().Length >= (ANIDLength + ANIDOffset))
                {
                    result = anid.ToString().Substring(ANIDOffset, ANIDLength);
                }
            }

            return result;
        }
    }
}

Other Extended Device information that can be retrieved using this class are:

    DeviceName
    DeviceUniqueId – if you are after an id to identify the user you should not use this, use Microsoft.Phone.Info.UserExtendedProperties with a parameter of “ANID”
    DeviceFirmwareVersion
    DeviceHardwareVersion
    DeviceTotalMemory
    ApplicationCurrentMemoryUsage
    ApplicationPeakMemoryUsage

More details on these extended properties can be found here

Nick

Happy 10000 hits time to introduce the team

Hi there, 

Today the team here at www.NickHarris.net made it to the 10,000 hit milestone 

Hit Graph

Hit Graph

We decided to down tools and celebrate with a team photo: 

Team photo

Team photo

Thats an ROI of 10000/10 = 1000 per team member 

And of course the blog would not be complete without mentioning that the photo was taken using a MS lifecam and a custom Silverlight App using the System.Windows.Media namespace specifically CaptureSource, VideoCaptureDevice and CaptureSource.CaptureImageAsync method 

If you’re sad because this blog post is coming to an end and your just not sure what to do with yourself then I can recommend that you go checkout this excellent .NET Blog www.thatdotnetguy.com

Now time to get back to that unpaid job of mine :)  

Nick

Search Marketplace on Windows Phone 7 with the MarketplaceSearchTask

This describes the straightforward task of how to search Microsoft Marketplace on Windows Phone 7 using the MarketpalceSearchTask. You should note that you can search by keyword and ContentType. Two usage examples would be as follows:

Example 1: Search Marketplace for “Rock” that is of content type Music – allows interesting application scenarios to be developed particularly for record labels like SONY
Example 2: Search Marketplace for “Your Company Name” that is of content type Application – useful if you want users of your application to be able to find other applications by you/your company.

Implementing Example 1:

  1. Add using statement to the Tasks namespace
  2. using Microsoft.Phone.Tasks;
  3. Create an instance of MarketplaceSearchTask set the ContentType and SearchTerms properties then call Show:
  4.     MarketplaceSearchTask mst = new MarketplaceSearchTask();
        mst.ContentType = MarketplaceContentType.Music;
        mst.SearchTerms = "Rock";
        mst.Show();
  5. Result: The first screen is the result, with the second screen being the resul of clicking on Rock Classic 100.
  6. MarketplaceSearchTask search for Rock Music

    MarketplaceSearchTask search for Rock Music

Implementing Example 2:
To search for applications all you need to do is change the mst.ContentType = MarketplaceContentType.Applications; and update the Search property

Note: if you have a specific target in marketplace in mind you can use MarketplaceDetailTask.

Enjoy,
Nick

Asynchronous Image download on Windows Phone 7

When running your solution on local and setting the Source property of the System.Windows.Controls.Image it is not visually apparent that the Image may take some period of time to download simplifying the code the following the original image swap out whereby i was using an arbitrary Uri to an image in Azure Blob Storage that would change at a predefined interval.

imgContent.Source = new BitmapImage(new Uri(arbitraryImageUriThatKeepsChanging));

As soon as the image is available from Azure Blob Storage – or any other hosting provider for that matter if you are not using a CDN and are a long way from your host then or the image is of a large size then it is likely that as soon as the image is set the image content becomes empty until the image is downloaded – i found this to be 10 to 30 seconds over the slow bandwidth of my phone.  To have an empty Image control on the screen was not acceptable so the simple solution is to pull down the image asynchronously using a WebClient then once downloaded update the Image.Source as follows:

Starting the Async download of the image:

WebClient wc = new WebClient();
wc.OpenReadCompleted += new OpenReadCompletedEventHandler(wc_OpenReadCompleted);
wc.OpenReadAsync(new Uri(arbitraryImageUriThatKeepsChanging), wc);

Handling the completed download and updating the image source – note: have intentionally removed the MVVM implementation here to minimise code in post if using MVVM setup the binding on the Image.Source property to the model Source.

void wc_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
   if (e.Error == null && !e.Cancelled)
  {
      try
      {
         BitmapImage image = new BitmapImage();
         image.SetSource(e.Result);
         imgContent.Source = image;
      }
      catch (Exception ex)
      {
          //Exception handle appropriately for your app
      }
  }
  else
  {
      //Either cancelled or error handle appropriately for your app
  }

Async download of Images from Azure to windows phone.

Note: WebClient executes on the UI thread if you wish to do this on a background thread and then later update the UI you should use HttpWebRequest and then Dispatcher within your response to update the UI thread.

Note: It would be interesting to configure the Azure CDN to see the improved performance once the node is distributed from a CDN node that is geographically close.

Nick

Monetize your Windows Phone 7 application with Microsft Advertising SDK

This post covers basic test Ads only.

1. Download the SDK – link can be found here http://advertising.microsoft.com/mobile-apps
2. Add a reference to the Microsoft.Advertising.Mobile.UI.dll
3. Add a reference in your XAML
 

xmlns:ad="clr-namespace:Microsoft.Advertising.Mobile.UI;assembly=Microsoft.Advertising.Mobile.UI"

4. Use one of the following three variants to display ads

<ad:AdControl AdModel="Contextual" ApplicationId="test_client" AdUnitId="Image300_50" />

<ad:AdControl AdModel="Contextual" ApplicationId="test_client" AdUnitId="Image480_80" />

<ad:AdControl AdModel="Contextual" ApplicationId="test_client" AdUnitId="TextAd" />

5. Job done:

Microsoft Advertising

Microsoft Advertising

Note: currently documentation seems to indicate only available to people with US tax identification number with aps targeted for the US market – more details here: http://advertising.microsoft.com/WWDocs/User/en-us/ForPublishers/Ads-in-Windows-Phone-7-Apps-FAQs.pdf

Those of you interested in a similar service for Australia please email me nicholas dot ian dot harris @ hotmail dot com or reply to this post with your contact details – i will keep the comments private.

Kind Regards,

Nick