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
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()
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"),
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();
Here is the output from running this sample Mvc application, the entire source code for this application is shared here.
Next time: How to authenticate your application with HealthVault through ASP.NET MVC