locked
Getting AccessDeniedException for an offline app RRS feed

  • Question

  • I have an offline application and my goal is to retrieve all records that are accessible for my application (by the way, I would appreciate it if someone can share his expertise with synchronizing HV's content). I am able to get a list of authorized people just fine, but I'm getting a HealthServiceAccessDeniedException (The authentication token element of the request is required for this method.) when I use searcher. Application's permissions are set to enable all access for all data types for both online and offline modes. Here is the code:

    var c = new OfflineWebApplicationConnection();
    c.Authenticate();
    
    foreach (var p in c.GetAuthorizedPeople())
       foreach (var r in p.AuthorizedRecords)
       {
          var accessor = new HealthRecordAccessor(c, r.Key);
          var searcher = accessor.CreateSearcher(Allergy.TypeId);
          var data = searcher.GetMatchingItems(); // HealthServiceAccessDeniedException 
       }


    I've tried relinking the application, but that didn't help. Somewhat similar topic from 2008:

    http://social.msdn.microsoft.com/Forums/en-US/31e3d29a-e917-4b34-b33d-3c0c308fd5e8/access-denied-offline-application-and-healthrecordaccessornewitem

    Any ideas?


    Tuesday, August 13, 2013 5:34 PM

Answers

  • It is [removed]

    Got it! Turns out that I have to create an offline connection for each patient (is that how it is supposed to be?). This code works:

    foreach (var p in new OfflineWebApplicationConnection().GetAuthorizedPeople())
    {
       var personConn = new OfflineWebApplicationConnection(p.PersonId);
       personConn.Authenticate();
    
       foreach (var r in p.AuthorizedRecords)
       {
          var accessor = new HealthRecordAccessor(personConn, r.Key);
          var searcher = accessor.CreateSearcher(Weight.TypeId);
          var data = searcher.GetMatchingItems(); // HealthServiceAccessDeniedException 
       }
    }
    

    Tuesday, August 13, 2013 7:25 PM

All replies

  • Can you share the AppID?
    Tuesday, August 13, 2013 5:58 PM
  • It is [removed]

    Got it! Turns out that I have to create an offline connection for each patient (is that how it is supposed to be?). This code works:

    foreach (var p in new OfflineWebApplicationConnection().GetAuthorizedPeople())
    {
       var personConn = new OfflineWebApplicationConnection(p.PersonId);
       personConn.Authenticate();
    
       foreach (var r in p.AuthorizedRecords)
       {
          var accessor = new HealthRecordAccessor(personConn, r.Key);
          var searcher = accessor.CreateSearcher(Weight.TypeId);
          var data = searcher.GetMatchingItems(); // HealthServiceAccessDeniedException 
       }
    }
    

    Tuesday, August 13, 2013 7:25 PM