locked
HealthServiceAccessDeniedException with message "The authentication token element of the request is required for this method" when GetMatchingItems() is called RRS feed

  • Question

  • Hello team,

    i m trying to create a healthvault enabled web application using patientconnect

    i have success in registering and validating patients with the app using offlinewebconnection, i used this doicument as a reference: http://msdn.microsoft.com/en-us/healthvault/cc507205

    but now i want to get data, following is the code

     

    OfflineWebApplicationConnection _offlinePatientConnection =
                            HealthVaultConnectionManager.CreateConnection(ControlHelperClass.ApplicationId, personInfo.PersonId);
                            offlineConnection.Authenticate();
                            //HealthClientApplication _healthClientApplication = HealthClientApplication.Create(ControlHelperClass.ApplicationId, new Guid("d32171dd-e150-4987-b13b-f985c3297b76"));
                            //new Guid("d32171dd-e150-4987-b13b-f985c3297b76")
                            //HealthClientAuthorizedConnection connection = _healthClientApplication.CreateAuthorizedConnection(vpc.PersonId);
                            HealthRecordAccessor hra = new HealthRecordAccessor(_offlinePatientConnection, vpc.RecordId);
                            HealthRecordSearcher searcher = hra.CreateSearcher();
                            HealthRecordFilter filter = new HealthRecordFilter(Height.TypeId); //height type from ms.health namespace :)
                            searcher.Filters.Add(filter);
                            HealthRecordItemCollection items = searcher.GetMatchingItems()[0];
                            searcher.Filters.Clear();
                            filter = new HealthRecordFilter(Weight.TypeId); //height type from ms.health namespace :)
                            searcher.Filters.Add(filter);
                            items = searcher.GetMatchingItems()[0];
                            searcher.Filters.Clear();
                            filter = new HealthRecordFilter(Allergy.TypeId); //height type from ms.health namespace :)
                            searcher.Filters.Add(filter);
                            items = searcher.GetMatchingItems()[0];
    
                            //foreach (Height height in items)
                            //{
                            //    string k = height.ToString();
                            //    int l = 12;
                            //}
                            HealthRecordItemCollection hrc = hra.GetItemsByType(Microsoft.Health.ItemTypes.Allergy.TypeId);

     


    However on the GetMatchingItems()[0] method call, I get the Microsoft.Health.HealthServiceStatusCode.AccessDenied exception (error code id: 11),  with message "The authentication token element of the request is required for this method."

    When creating the HealthClientApplication, i have used provider id (sample practitioner guid) as application id and id from certificate as master application id, i hope i m doing every thing ok.

    this is the stack trace

     

    Microsoft.Health.HealthServiceAccessDeniedException was unhandled by user code
      Message=The authentication token element of the request is required for this method.
      Source=Microsoft.Health
      ErrorCodeId=11
      StackTrace:
           at Microsoft.Health.EasyWebRequest.WaitForCompletion()
           at Microsoft.Health.EasyWebRequest.Fetch(Uri url)
           at Microsoft.Health.EasyWebRequest.Fetch(Uri url, IEasyWebResponseHandler customHandler)
           at Microsoft.Health.HealthServiceRequest.ExecuteInternal()
           at Microsoft.Health.Web.OfflineWebApplicationConnection.ExecuteRequestWithRetry(HealthServiceRequest request)
           at Microsoft.Health.HealthServiceRequest.Execute()
           at Microsoft.Health.HealthRecordSearcher.Execute()
           at Microsoft.Health.HealthRecordSearcher.GetMatchingItems()
           at ViewPatientDetails.chkIfCurrentPatientAuthorized() in d:\My.Docs\HiS\HealthVault\sdk installer\Trey Research Online EMR Multi-physician Practice\website\ViewPatientDetails.aspx.cs:line 87
           at ViewPatientDetails.Page_Load(Object sender, EventArgs e) in d:\My.Docs\HiS\HealthVault\sdk installer\Trey Research Online EMR Multi-physician Practice\website\ViewPatientDetails.aspx.cs:line 37
           at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
           at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
           at System.Web.UI.Control.OnLoad(EventArgs e)
           at System.Web.UI.Control.LoadRecursive()
           at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
      InnerException:


    maqk loves to code

    • Edited by maqkhan Tuesday, November 29, 2011 12:32 PM
    Friday, November 25, 2011 2:28 PM

Answers

  • I fixed my self by initializing the offlinewebapplication object correctly. I have been extending the trey research health vault application and used their initialization method.

     

    now the situation is changed, the above error is not ocming but the items returned are 0. Nothing gets returned can u guys help ? should I create a new thread ?


    maqk loves to code
    • Marked as answer by maqkhan Monday, November 28, 2011 4:25 PM
    Monday, November 28, 2011 4:25 PM

All replies

  • I fixed my self by initializing the offlinewebapplication object correctly. I have been extending the trey research health vault application and used their initialization method.

     

    now the situation is changed, the above error is not ocming but the items returned are 0. Nothing gets returned can u guys help ? should I create a new thread ?


    maqk loves to code
    • Marked as answer by maqkhan Monday, November 28, 2011 4:25 PM
    Monday, November 28, 2011 4:25 PM
  • Can you explain your scenario more? How is the user going to use your system, how do they connect to healthvault, etc.?

    HealthClientApplication is intended for client applications, not web applications. For a web application you should start with the sample applications in the SDK, or you can use Application Manager to create a new one.

    Monday, November 28, 2011 5:30 PM
  • well thanks for the response Eric

    I downloaded a sample web application from codeplex with the applicaion id "d32171dd-e150-4987-b13b-f985c3297b76" named "Trey Research Online EMR" (http://healthvaultd2cv2.codeplex.com/)

    Its a web application and i am simply writing custom code to get simple biographic / medication information like height, weight, allergies etc.

    The system is using patientconnect and thats why i m using OfflineWebApplicationConnection.

    The code to fetch things are in the first post of this thread and its now connecting, authenticating but not fetching any data. I can share other resources/colde if you need.

    My scenario is more like the one described in this thread: http://social.msdn.microsoft.com/forums/en-us/healthvault/thread/48A8FD63-E8DD-42E7-840F-1575D12B5F0D

    if you see the last post of Shrivallabh in the thread, i m in the same position :D, all done, just not getting any thing returned?

    Also should i rename this thread to explain the current scenario or create a new thread? waiting anxiously


    maqk loves to code

    • Edited by maqkhan Tuesday, November 29, 2011 7:49 AM
    Tuesday, November 29, 2011 7:16 AM
  • If your scenario is like the one in the thread that you reference, I would not recommend using that application as a starting point; I think it will be significantly more complex than using our other samples, and you are currently using parts of the system together in a way that I wouldn't recommend.

    I need more clarity on your scenario. Is it:

    1) A web application that connects to HealthVault and only accesses data while the user is using the application (what we call an online application).

    2) An web application that does #1, and also an additional application that will access the user's data while the user isn't using the application (what we call an offline application).

    If it's the first, then you don't need to use offline (or patient connect) at all.

    If it's the second, then you will need offline access, but you will not need patient connect.

    The only systems that need patient connect are those that don't have an online component at all. Unless that is the case, we highly recommend not using patient connect because the connection process is harder for users than an online application.

     

    Tuesday, November 29, 2011 5:19 PM
  • Thanks Eric once again, amazingly my problem is solved. It was an access issue and somehow, the application i was using did not sent an Access Denied exception. When i used the same application iD, person ID and record ID with the default application, it started giving me access denied error.I will not be able to further investigate what made it override the Access Denied exception and rather return null collections cause i have other goals to achieve :D

    As a solution, I made a whole new application, granted all access in online and offline rules, created a whole new desktop application and used the same code for that person.

    This thread is answered. Thanks Eric once again. As more as i learn healthvault, i will do my best to contribute here.


    maqk loves to code
    Thursday, December 1, 2011 2:03 PM