locked
Stringing together HealthVault, WCF, and SilverLight RRS feed

  • Question

  • OK I have two independent pieces working now but I can't quite see how to connect them. I have a simple HealthVault app that can open up my record and look at Medications.

    Separately I have a SliverLight application that communicates through WCF to local databases and an analytical engine.

    I have an simple project that will authenticate to HV and then launch my Silverlight XAP.

    But what I really need is for the WCF to somehow get my authentication context and communicate to HealthVault and the SilverLight app at the same time.

    Any suggestions would be appreciated.

    Thanks,
    Don Rule
    Thursday, February 5, 2009 4:54 AM

Answers

  • Try WebApplicationUtilities.LoadPersonInfoFromoCookie(HttpContext) and see if you get the personinfo

    This should work as long as the url (since then cookies are shared) namespace of your HV app and silverlight app is same and both have same appids in web.config etc...


    Raj
    Raj HealthVault Developer Tool http://xray.getrealconsulting.com
    • Marked as answer by DonHRule Thursday, February 5, 2009 6:26 PM
    Thursday, February 5, 2009 5:51 PM

All replies

  • I am not very sure what the implications are when you use WCF or silverlight specifically... but in general there are few ways you could potentially work here when you want to pass healthvault user contexts across applications....

    Using Offline access

    One straight forward way is to use offline authentication.  Here, when your user authenticates with Healthvault for first time, you store his PersonId and RecordId to the the database and these values can be reused later by another application.  The good (and equally bad) thing here is that the application can access the user's health record anytime at will even when the user is not online and has logged off from his HealthVault session.  Unless you have compelling reasons, avoid this mode.  Obviously you need to enable offline access for application id blah blah...

    You could then write a webservice in .net using HV SDK which the Silverlight application (again I dont know if a silverlight can use HV SDK directly) can call passing in the usercontext.  The webservice will then look into the database, get the PersonId, RecordId that was stored, and can access the user's record directly and pass the results back to silverlight app. 

    Without using offline acess

    This approach would be ideal if the life span of the silverlight application session is only when the user online authenticated to HealthVault in a browser (which I assume is the case here).  When you get authenticated to HealthVault, each time HealthVault passes back your application a wctoken (which the SDK abstracts and saves it in cookie and constructs PersonInfo objects each time thereon).  The PersonInfo object is Marshallable as XML and could be passed to another application context.  You can pass this object to the other application which can in turn make HV calls ...


    HTH

    Raj



    Raj HealthVault Developer Tool http://xray.getrealconsulting.com
    Thursday, February 5, 2009 12:04 PM
  • The second approach is much preferable. I know that WCF has access to the cookies as described here

    http://jonas.follesoe.no/WCFAuthenticationServicesSilverlightAndSmellyCookies.aspx

    So it seems like the initial authentication with HealthVault will prime the browser with the credential, when I make the call to WCF from SilverLight, the credential should be available, I just need to know how I take advantage of the credential in my WCF code to work on behalf of the user to get their HealthVault record. Some other sites mention a MembershipProvider for Windows Live IDs that WCF can readily plug into. Is there an equivalent for HealthVault?

    Thanks

    Thursday, February 5, 2009 4:56 PM
  • Ok Here is an experiment that I tried:

    1. In my SilverLight web application create a new SilverLight WCF service
    2. Derive the Service class from HealthServicePage (below)
    3. Plug the Silverlight appplication into the service


    This would have been beautiful if deriving from HealthServicePage simply caused the wcToken to be passed to HealthVault but alas when I tested this PersonInfo was null.

    I think that this is the general direction though - Is there a sample somewhere of someone building a web service and using the HealthVault authentication token?


    using Microsoft.Health;

    using Microsoft.Health.Web;

    using Microsoft.Health.ItemTypes;

     

    namespace SilverlightApplication2.Web

    {

        [ServiceContract(Namespace = "")]

        [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]

        public class Service1 : HealthServicePage

        {

            [OperationContract]

            public string DoWork()

            {

                return PersonInfo.Name.ToString();

            }

     

        }

    }

    Thursday, February 5, 2009 5:35 PM
  • I dont think MembershipProvider for Live Id is applicable here. 

    I would assume that the following approch shud work.

    In your WCF code , you would do code in the  following lines


    PersonInfo info = new PersonInfo();
    info.UnMarshal(....);

    HealthRecordSearcher searcher = info.SelectedRecord.CreateSearcher();

    // do search..

    Let me know if it works.   Honestly, I havent experimented in similiar lines - but having read the source code of SDK, my guess is that this approach should work.



    Raj





    Raj HealthVault Developer Tool http://xray.getrealconsulting.com
    Thursday, February 5, 2009 5:43 PM
  • Try WebApplicationUtilities.LoadPersonInfoFromoCookie(HttpContext) and see if you get the personinfo

    This should work as long as the url (since then cookies are shared) namespace of your HV app and silverlight app is same and both have same appids in web.config etc...


    Raj
    Raj HealthVault Developer Tool http://xray.getrealconsulting.com
    • Marked as answer by DonHRule Thursday, February 5, 2009 6:26 PM
    Thursday, February 5, 2009 5:51 PM
  • That was it!!!

     In the end it was pretty simple.

    Now my next step is to marshal stuff in the personinfo over to Silverlight. WCF doesn't let me just return PersonInfo so it seems like its marshaller is not compatible for some reason. 

    I could just send it to XML and toss it over the wire but Silverlight won't accept the HealthVault DLLs on the other side for me to reconsititute them into proper objects.

    So I can:
    a. Send as XML and use Linq on the other side to process them
    b. Create my own structures that will be automatically marshalled and then do the format-munging on the server side

    If there were a class definition of the HealthVault structures that was independent of the dlls (like a good old fashioned .h file) that may do the trick - is there any such thing?


    Thanks again, this is going to be a great solution.

    Don


    [OperationContract]
    public string DoWork()
    {
        
    PersonInfo pi = WebApplicationUtilities.LoadPersonInfoFromCookie(HttpContext.Current);
        
    return pi.Name.ToString();
    }

    Thursday, February 5, 2009 6:26 PM