Unable to subscrive to events (SubscriptionManager + OfflineWebApplicationConnection). "This method cannot be invoked when the person is offline."
-
Wednesday, April 11, 2012 6:01 PM
I'm getting the exception displayed in the title (This method cannot be invoked when the person is offline.) when I try to subscribe to the eventing capabilities of Health Vault.
A few details:
- The measurements I'm trying to read have offline permission (settings from my healthvault app)
- The return url IS NOT HTTPS
- The return url is a valid (non localhost) url visible by other internet applications.
- The site is MVC 3 based and I'm not doing any inheritance from HelthVault pages.
- If I use Guid.Empty as person context, I get the "url must be https" exception. If I write the url using https I get this: Subscribing application action urls must include at top level domain and at least one sub domain.
This is the code I'm using to do the subscription (I've obfuscated the site url because I'm not in position to share it at this time):
private void HandleHealthVaultSubscriptions() { HealthVaultSettings settings = ProviderManager.GetHealthVaultSettings(CurrentUser); // Establish the offline connection OfflineWebApplicationConnection offlineConn = new OfflineWebApplicationConnection( new Guid(ConfigurationManager.AppSettings["ApplicationId"]), ConfigurationManager.AppSettings["HealthServiceUrl"], settings.PersonId); offlineConn.Authenticate(); SubscriptionManager manager = new SubscriptionManager(offlineConn); HealthRecordItemChangedSubscription subscription = null; //prepare filter: HealthRecordItemChangedFilter filter = new HealthRecordItemChangedFilter(); filter.TypeIds.Add(BloodPressure.TypeId); filter.TypeIds.Add(BloodGlucose.TypeId); filter.TypeIds.Add(Weight.TypeId); subscription = CreateSubscription(filter); manager.Subscribe(subscription); } private HealthRecordItemChangedSubscription CreateSubscription(HealthRecordItemChangedFilter filter) { NotificationAuthenticationSharedKeyInfo sharedKeyInfo = new NotificationAuthenticationSharedKeyInfo("Version-1"); sharedKeyInfo.Key = Convert.FromBase64String(ConfigurationManager.AppSettings["HVEventingSharedKeyValue"]); //get the url for event handler: string handlerUrl = "http://MY-SITE-URL/ProviderNotification/HealthVault"; CommonSubscriptionData common = new CommonSubscriptionData(new HttpNotificationChannel(new Uri(handlerUrl)), sharedKeyInfo); HealthRecordItemChangedSubscription subscription = new HealthRecordItemChangedSubscription(common); subscription.Filters.Add(filter); return subscription; }
Thanks in advance,
Angel
- Edited by Angel Arcoraci Wednesday, April 11, 2012 6:07 PM
All Replies
-
Wednesday, April 11, 2012 6:54 PMOwner
Hi,
It looks like there are a few things going on...
- Yes, do not use a person-id on the connection. The request only uses application identity.
- The subscription url must be https.
- The last error indicates that your application's action-url must not be a host on the local network (no subdomain). It isn't yet complaining about the length of your subscription url.
You can check your application's action-url here: https://config.healthvault-ppe.com
--Rob
-
Wednesday, April 11, 2012 7:04 PM
Rob,
thanks a lot for your fast answer. I'll give it a try as soon as I configure everything up so I can tag this as solved (if it works !).
Bests,
Angel
-
Thursday, April 12, 2012 6:35 PM
This made me wonder, How does eventing works ? why/when do we need to call that code?
For example, when working with OAuth, you usually subscribe a given user to a given notification. However, if we are not using the person-id, I assume it is subscribing the entire application for all the user's who have allowed such application. Which means, that code should only be executed once. Is this correct ?
In addition, I'm also wondering about the Action URL which needs to be configured in the Application Configuration Center. For what it is used?
If anyone could clarify that, It would be really appreciated !
Thanks
-
Friday, April 13, 2012 6:18 PMOwner
Hi,
Yes the subscription is at the application level. Your application will receive notification for all users who have authorized your application. You only need to create a single subscription.
Here is some information about the action-url: http://msdn.microsoft.com/en-us/library/ff803625.aspx
--Rob

