Associating Mood Tracker With HealthVault #3

Sorry for the delay in installment #3 in the series of how to write a WP7 app for HealthVault! The code for this application is now hosted on github.

In order for the Mood Tracker application to work with HealthVault we will get appropriate application creation credentials from the HealthVault Service and authorize them through the user with HealthVault Shell.

1. To get the credential from HealthVault Service the application contacts the HealthVault service to get application creation Url.

The code for that is outlined in MyMood.xaml.cs

 void MainPage_Loaded(object sender, RoutedEventArgs e)

void DoShellAuthentication(object sender, HealthVaultResponseEventArgs e)


            string url;

            if (_addingRecord)
                url = App.HealthVaultService.GetUserAuthorizationUrl();

2. The application creation needs to be validated on behalf of the user.

The best mechanism to achieve this is by having a page with a hosted browser which redirect appropriately to HealthVault and closes the browsers and navigated back to page on a successful authorization.

Following is the code in HostedBrowserPage.xaml :

      void c_webBrowser_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
            if (e.Uri.OriginalString.Contains("target=AppAuthSuccess"))
                Uri pageUri = new Uri("/MyMood.xaml", UriKind.RelativeOrAbsolute);

                Deployment.Current.Dispatcher.BeginInvoke(() =>

        void HealthVaultWebPage_Loaded(object sender, RoutedEventArgs e)
            string url = App.HealthVaultShellUrl;

            c_webBrowser.Navigate(new Uri(url));

Note that on success the Application is being redirected to MyMood.xaml which is our landing page!

Here is flow of how the above authentication works!


Step1. Home page      Step2.Sign-in & Auth  Step3. Mood track in action!

Next time: Adding the emotional state data type to Mood Tracker

Previous Post: Getting Started

.csharpcode, .csharpcode pre
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
background-color: #f4f4f4;
width: 100%;
margin: 0em;
.csharpcode .lnum { color: #606060; }

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.