Проблемы с чтением контактных адресов в EWS.Все контакты читают дисплей «Указанный ключ отсутствует в словаре». - PullRequest
0 голосов
/ 15 июня 2019

Невозможно получить первый адрес электронной почты для отображения. Все записи отображаются так: «Данный ключ отсутствует в словаре». Определенно есть адреса электронной почты, связанные с контактами. Вот код ....

static void Reademail()
{
    ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013);
    service.UseDefaultCredentials = true;
    service.AutodiscoverUrl("validaddress@ddd.com");
    // Get the number of items in the contacts folder. To limit the size of the response, request only the TotalCount property.
    ContactsFolder contactsfolder = ContactsFolder.Bind(service,WellKnownFolderName.Contacts,new PropertySet(BasePropertySet.IdOnly, FolderSchema.TotalCount));

    // Set the number of items to the number of items in the Contacts folder or 50, whichever is smaller.
    int numItems = contactsfolder.TotalCount < 50 ? contactsfolder.TotalCount : 50;


    // Instantiate the item view with the number of items to retrieve from the Contacts folder.
    ItemView view = new ItemView(numItems);

    // To keep the request smaller, request only the display name property.
    view.PropertySet = new PropertySet(BasePropertySet.IdOnly, ContactSchema.DisplayName);

    // Retrieve the items in the Contacts folder that have the properties that you selected.
    FindItemsResults<Item> contactItems = service.FindItems(WellKnownFolderName.Contacts, view);


    // Display the list of contacts. 
    foreach (Item item in contactItems)
    {
        if (item is Contact)
        {
            Contact contact = item as Contact;
            Console.Write(contact.DisplayName + " ");
            try
            {
                Console.WriteLine(contact.EmailAddresses[EmailAddressKey.EmailAddress1].Name);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
    }
    Console.ReadKey();
}

.....

1 Ответ

0 голосов
/ 18 июня 2019

Исправление, которое я обнаружил, заключалось в использовании оператора contact.Load. Хотя, возможно, не самый эффективный, так как маскирует обратный вызов в EWS. Очевидно, это загружает основной класс, и тогда адреса электронной почты становятся видимыми.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...