Share via


Starting a Polling Subscription

Once the RemotePresenceView object for a polling subscription is created and initialized, you can start the polling subscription by calling the StartSubscribingToPresentities on the RemotePresenceView object of the Polling type.

As in a persistent subscription, Microsoft Unified Communications Managed API (UCMA) 3.0 assigns calendarData, contactCard, note, noteHistory, state, services as the default subscription category names in a polling subscription. You can reset them by calling the RemotePresenceView.SetPresenceSubscriptionCategoriesForPolling method before starting the subscription. The polling interval has a default value of 5 minutes and you can reset this value by calling the RemotePresenceViewSettings.SetPresenceSubscriptionCategoriesPollingInterval when the RemotePresenceView of the Polling type is instantiated.

Polling subscription is an asynchronous process and involves multiple SUBSCRIBE requests, each being submitted on behalf of the user at the prescribed time intervals, until the subscription is terminated. With each successful SUBSCRIBE request, the server returns the requested results in PresenceNotificationReceived events. The client will not receive any presence notifications until the subscription state changes to Polling and unless the client has registered the required event handlers with the RemotePresenceView object. For information about registering for persistent subscription events, see Handling Events to Receive Presence Publications.

To stop the subscription, call the StartUnsubscribingToPresentities method on the RemotePresenceView object. The terminated presence view object can be used to restart the subscription.

The following code example shows how to start and stop a polling subscription.

        #region Polling subscription
        public void SetPollingCategories(params string[] categoryNames)
        {
            if (categoryNames == null || categoryNames.Length == 0)
                return;
            _pollingPresenceView.SetPresenceSubscriptionCategoriesForPolling(categoryNames);
        }

        public void StartPollingSubscription(params string[] sipUris)
        {
            IEnumerable<string> uris = sipUris as IEnumerable<string>;
            this.StartPollingSubscription(uris);
        }

        public void StartPollingSubscription(IEnumerable<string> sipUris)
        {
            List<RemotePresentitySubscriptionTarget> sipUriList = new List<RemotePresentitySubscriptionTarget>();
            foreach (string sipUri in sipUris)
                sipUriList.Add(new RemotePresentitySubscriptionTarget(sipUri));
            _pollingPresenceView.StartSubscribingToPresentities(sipUriList.ToArray());
        }

        public void StopPollingSubscription(IEnumerable<string> sipUris)
        {
            _pollingPresenceView.StartUnsubscribingToPresentities(sipUris);
        }

        public void StopPollingSubscription()
        {
            IEnumerable<string> sipUris = _pollingPresenceView.GetPresentities();
            if (sipUris != null)
                this.StopPollingSubscription(sipUris);
        }

        #endregion polling subscription