Partilhar via


Starting a Persistent Subscription

Once the RemotePresenceView object for a persistent subscription is created and initialized, you can start the persistent subscription by calling StartSubscribingToPresentities method on the RemotePresenceView instance of the Persistent type.

By default, Microsoft Unified Communications Managed API (UCMA) 3.0 includes calendarData, contactCard, note, noteHistory, state, and services as the subscription category names in a persistent subscription. The subscription category names can be modified only before any SUBSCRIBE request is made. You can change this list by setting the UserEndpointSettings.Presence.RemotePresenceSubscriptionCategories property when UserEndpoint is instantiated. For an example on how to modify this list of subscription categories, see the code example in Signing in to Lync Server.

Persistent subscription is an asynchronous process and involves a single SUBSCRIBE request submitted on behalf of the user. After the client successfully starts the subscription, the server returns the requested results in PresenceNotificationReceived events. When a new publication is detected or an existing publication is modified, the server will return the new results in more events. This process continues until the subscription is terminated.

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 persistent subscription.

        #region Persistent subscription

        public void StartPersistentSubscription(IEnumerable<string> uris)
        {
            if (uris == null)
                return;
            List<RemotePresentitySubscriptionTarget> targets = new List<RemotePresentitySubscriptionTarget>();
            foreach (string uri in uris)
                targets.Add(new RemotePresentitySubscriptionTarget(uri));
            _persistentPresenceView.StartSubscribingToPresentities(targets);
        }

        public void StopPersistentSubscription(IEnumerable<string> uris)
        {
            if (uris == null)
                return;
            _persistentPresenceView.StartUnsubscribingToPresentities(uris);
        }


        public void StopPersistentSubscription()
        {
            this.StopPersistentSubscription(_persistentPresenceView.GetPresentities());
        }


        #endregion Persistent subscription

The client will not receive any presence notifications until the subscription state changes to Subscribed 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.