Lync 2013 UCMA WCF Web Service

563 views Asked by At

What I want to do is create a WCF service just to get the availability of a user. I have gone through the following quick-start example: Name: SubscribePresence http://msdn.microsoft.com/en-us/library/office/dn454835(v=office.15).aspx

I have managed to do this but i feel that its not the most efficient way to just get a users availability.

At the moment I create a end point subscribe to a users presence and wait for the response to come back and from that i get the users availability. (I'm simplifying this down).

What I would ideally like though is just to quickly get a users availability without subscribing to a users presence and close the connection as soon as i have retrieved the availability.

I was wondering if anyone knows of an example that i can have a look at or that they have implemented themselves

any advice would be appreciated

1

There are 1 answers

1
w5l On

You can also do a one-time presence query. From MSDN:

If a one-time presence query to a remote presentity is desired, creating a view and tearing it down is a suboptimal solution for an application. In addition, the application needs to wait and track whether all presence information has been received.

An alternative is to use the BeginPresenceQuery(IEnumerable<String>, [], EventHandler<RemotePresentitiesNotificationEventArgs>, AsyncCallback, Object) and EndPresenceQuery(IAsyncResult) methods on the endpoint’s PresenceServices property.

See http://msdn.microsoft.com/en-us/library/office/hh383136%28v=office.14%29.aspx

Example

You can call the presence query like this. The null argument on 3rd position is the event handler which will fire when presence is recieved, it's not required since we process the results of the EndPresenceQuery instead. You could also pass an eventhandler and not care about the results of the EndPresenceQuery, thats up to you.

endpoint.PresenceServices.BeginPresenceQuery(
    new[] { "sip:[email protected]" }, // Collection of sip addresses to query
    new[] { "state" }, // Collection of presence catrgories to query
    null, // The eventhandler to call when presence is recieved
    (ar) => {
        var result = endpoint.PresenceServices.EndPresenceQuery(ar);
        // process the recieved containers in 'result' here.              
    }, 
    null); // The state object

However, when you run a WCF service for presence which will be queried multiple times, I would say it might be better to subscribe to presence than to do single queries every time. I build a similar system once with the following logic:

  1. Get an incoming presence request on WCF.
  2. If this SIP uri presence is known to the WCF service (is subscribed), return immediately the cached presence.
  3. If it is not known, subscribe to the presence.
  4. When presence is recieved, return the result and add the presence to the cache.
  5. Any time a subscribed user updates their presence, an event is fired to update the cache.
  6. If no presence queries are recieved for a single user for a certain period of time, unsubscribe from the presence and remove from cache.

The main advantage here is that for multiple subsequent queries for the same user's presence, you do not query the Lync server each time. Your service responses will be a lot faster, and you get presence pushed rather than having to poll for it each time.