2

We are using the Lync SDK to fetch contact information and phone numbers to display in our application. Lync search control is used and on right click on a contact, we try to fetch the phone numbers of the contact.

This has intermittent issue of not returning the complete information in the contact card in Lync search control. At times it works good but other times, it fails to return complete phone number list.

List<object> endPoints = new List<object>();
List<ContactInformationType> _ContactInformationList = new List<ContactInformationType>();
_ContactInformationList.Add(ContactInformationType.EmailAddresses);
_ContactInformationList.Add(ContactInformationType.ContactEndpoints);
try
{
    if (!string.IsNullOrWhiteSpace(sipuri))
    {
        Contact _contact = lyncObj.ContactManager.GetContactByUri(sipuri);
        Microsoft.Lync.Controls.ContactCard _contactCard = new Microsoft.Lync.Controls.ContactCard();
        _contactCard.Source = contact.GetContactInformation(ContactInformationType.EmailAddresses);
        ContactSubscription _contactSubscription = lyncObj.ContactManager.CreateSubscription();
        _contactSubscription.AddContact(_contact);
        _contactSubscription.Subscribe(ContactSubscriptionRefreshRate.High, _ContactInformationList);
        // add sleep to subscribe 
        System.Threading.Thread.Sleep(500);
        var telephoneNumbersList = (List<object>)_contact.GetContactInformation(ContactInformationType.ContactEndpoints);
        foreach (object endPoint in telephoneNumbersList)
        {
            Logger.LogInfo(((ContactEndpoint)endPoint).DisplayName + " " + ((ContactEndpoint)endPoint).Type.ToString());
        }
        endPoints = telephoneNumbersList.Where<object>(N => ((ContactEndpoint)N).Type == ContactEndpointType.HomePhone || ((ContactEndpoint)N).Type == ContactEndpointType.MobilePhone || ((ContactEndpoint)N).Type == ContactEndpointType.OtherPhone || ((ContactEndpoint)N).Type == ContactEndpointType.WorkPhone).ToList<object>();
    }
}

Several times, the complete contact information is not returned. Only one out of two phone numbers are seen in the contact information. While some time all phone numbers are returned.

If I try to search the same contact over Microsoft Lync search I can see all phone numbers in contact card.

Could you please suggest what could be the root cause and probable solution?

Alexander Farber
  • 21,519
  • 75
  • 241
  • 416

1 Answers1

1

You really shouldn't be doing a "sleep" to wait for the results. The data can take awhile to come back.

What you should be doing is adding a ContactInformationChanged handler. The event handler will be called everytime the subscribed data changes/loads.

This API doesn't really suit a access pattern of querying for the data then returning it (which looks to be what you are trying to do). It's really for a pattern of subscribing to the data and you will be then be called when it's loaded or updated. Most useful when displaying the contact information in a GUI and the contact information gets "filled" in over time when it loads.

Also remember you need to call ContactSubscription.Unsubscribe when you are finished with the contact.

The Lync Client caches contact data, that is why when you call it a second time it's comes back with all data prepopulated.

Shane Powell
  • 13,698
  • 2
  • 49
  • 61