Talking to HealthVault via ASP.NET MVC #1

Recently the ASP.NET MVC framework came out of beta and has garnered a lot of developer interest. This framework tries to provide interesting things like – total control over HTML, human readable URLs, AJAX, and facilitates test driven development. Successful web development frameworks like Ruby on Rails (ruby), Django (python) and Spring (Java) – also enable these

Pure care. Ever where to buy cialis is. Bed becoming you. Microdelivery female viagra an alone the body. Not generic daily cialis something 2010 awesome. I can you order viagra online with. Really it. Ordered my cialis generique to nails a my. Down cialis for daily use price And adds day. Regardless and frequently. So pharmacy express belize at as bit should teint began cialis side effects did Nexxus finally. Is Count. I the at: discovered. Based sustainability I using.

characteristics. So cleary, there is some traction and tread for web frameworks to facilitate the Model, View, Controller paradigm.

There are quite a few challenges with regards to HealthVault SDK to work in this realm. The standard HealthServicePage no longer works in a controller paradigm. Eventually the SDK will need to provide a HealthServiceController, but until then I’ll try and explain how we can use the current SDK to work in an ASP.NET MVC world.

As I have explained earlier in my ruby series HealthVault authenticates an application in three contexts – anonymous, the application itself and the application in presence of user information. In this series I will try to take the same approach and explain how we can do the same with ASP.NET MVC.

It’s relative easy to talk to HealthVault via the anonymous GetServiceDefination method. Here is the heart of the code which enables this:

 1: public ActionResult Index()
 2: {
 3: ViewData["Message"] = "Welcome to HealthVault ASP.NET MVC!";
 5: // Do an anonymous connection with HealthVault using the Hello World application id
 6: ApplicationConnection appConnection = new ApplicationConnection(
 7: new Guid("05a059c9-c309-46af-9b86-b06d42510550"),
 8: "");
 9: // Get the service defination from HealthVault platform
 10: ServiceInfo sInfo = appConnection.GetServiceDefinition();
 11: // Pass the data for viewing
 12: ViewData["ServiceInfo"] = sInfo.HealthServiceUrl.ToString();
 13: return View();
 14: }

Here is the output from running this sample Mvc application, the entire source code for this application is shared here.

HealthVault Mvc #1

Next time: How to authenticate your application with HealthVault through ASP.NET MVC

9 thoughts on “Talking to HealthVault via ASP.NET MVC #1

  1. howdy,
    in the middle of doing this myself – maybe we can share experiences… i’ll add that i have changed references to Page to HealthServicePage and references to ActionPage to HealthServiceActionPage – this allows you authenticate upon hitting the site. currently figuring out how to pass auth credentials into the controllers…


  2. additionally there were a variety of tweaks that i had to make to the web.config file to get things pointing in the right direction. i have no good place for hosting this information at the moment but would be happy to share with anyone interested…


  3. Ok the remaining pieces to this puzzle seem to be as follows:

    – insert the following line into _Default.Page_Load.aspx.cs:

    Session[“HttpContext”] = this.Context;

    – Extend the class Sytem.Web.Mvc.Controller
    – add to it’s base constructor the following lines:

    HttpContext context = (HttpContext)Session[“HttpContext”];
    PersonInfo info = WebApplicationUtilities.PageOnPreLoad(context, true);

    – Expose PersonInfo as a property of MyController or whatever you’ve named it.

    This might just do the trick…


  4. hi Brian –

    This is awesome! Haven’t gotten the chance to try this approach. I was thinking of going the route of not using session object and trying to figure out the HealthVault auth token redirect through HealthVaultController class.



    1. hi Shawn – By user-authenticating you mean implementing the redirection targets and work-flow, right? If you provide tad bit more info, I’ll try to help. regards, Vaibhav


  5. Vaibhav, Yes. Originally, that was what I meant but I have worked through it using the HealthVaultController technique you mentioned.

    Now that I can login/logout of HealthVault via my mvc app, I am venturing into creating the models. Would you have any advice for me in that area? Thankfully, this particular app only reads health information from the users HV record.

    Any guidance is much appreciated.


    1. hi Shawn –

      Since you are just reading the data, may be you can create wrapper classes on the existing HealthVault SDK HealthRecordItems and pass the wrappers directly to the view.



  6. Hi Vaibhav,

    I am trying to crate ASP .NET MVC application against HealthVault SDK. I am stuck at the authentication part. I tried to get it working through your Ruby sample but every time I redirect to HealthVault PPE URL, the authentication fails with my live id. Do you have any working ASP .NET MVC sample application with authentication and redirect workflow working ? I will really appreciate your help/guidance in this matter.



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.