EWS с помощью BindToItems () извлекает несовместимый элемент - PullRequest
0 голосов
/ 24 сентября 2019

У меня есть набор почтовых ящиков, из которых мне нужно извлечь элементы за определенный промежуток времени.Чтобы ускорить процесс и не выполнять вызов для каждого элемента, я использую метод BindToItems (), с помощью которого одним вызовом EWS можно получить более одного элемента.На данный момент я установил размер пакета на 250. С большинством почтовых ящиков все работает нормально.но с некоторыми конкретными почтовыми ящиками я получаю

Ссылка на объект не установлена ​​на экземпляр объекта

, когда я пытаюсь выполнить следующую строку:

foreach (Attachment attachment in message.Attachments)

всегда по какому-то определенному индексу коллекции предметов, например 59 для электронной почты1, 124 электронной почты2, 12 электронных писем3 и т. Д.

Вот код, который я использую:

FindItemsResults<Item> findResults = service.FindItems(results.Folders.Single().Id, searchFilterCollection, view);
ServiceResponseCollection<GetItemResponse> items = service.BindToItems(findResults.Select(r => r.Id), propertySet);
foreach (GetItemResponse item in items){
   EmailMessage message = (EmailMessage)item.Item;
   foreach (Attachment attachment in message.Attachments){
        //do something
   } 
}

Здесь выбраны свойства:

 PropertySet propertySet = new PropertySet();
        propertySet.Add(ItemSchema.ConversationId);
        propertySet.Add(ItemSchema.Culture);
        propertySet.Add(ItemSchema.DateTimeCreated);
        propertySet.Add(ItemSchema.DateTimeReceived);
        propertySet.Add(ItemSchema.DateTimeSent);
        propertySet.Add(ItemSchema.EffectiveRights);
        propertySet.Add(ItemSchema.HasAttachments);
        propertySet.Add(ItemSchema.Id);
        propertySet.Add(ItemSchema.Importance);
        propertySet.Add(ItemSchema.InReplyTo);
        propertySet.Add(ItemSchema.IsAssociated);
        propertySet.Add(ItemSchema.IsDraft);
        propertySet.Add(ItemSchema.IsFromMe);
        propertySet.Add(ItemSchema.IsResend);
        propertySet.Add(ItemSchema.IsSubmitted);
        propertySet.Add(ItemSchema.IsUnmodified);
        propertySet.Add(ItemSchema.ItemClass);
        propertySet.Add(ItemSchema.LastModifiedName);
        propertySet.Add(ItemSchema.LastModifiedTime);
        propertySet.Add(ItemSchema.ParentFolderId);
        propertySet.Add(ItemSchema.Sensitivity);
        propertySet.Add(ItemSchema.Size);
        propertySet.Add(ItemSchema.Attachments);
        propertySet.Add(EmailMessageSchema.ConversationIndex);
        propertySet.Add(EmailMessageSchema.ConversationTopic);
        propertySet.Add(EmailMessageSchema.From);
        propertySet.Add(EmailMessageSchema.InternetMessageId);
        propertySet.Add(EmailMessageSchema.IsRead);
        propertySet.Add(EmailMessageSchema.References);
        propertySet.Add(EmailMessageSchema.Sender);
        propertySet.Add(EmailMessageSchema.CcRecipients);
        propertySet.Add(EmailMessageSchema.ToRecipients);
        propertySet.Add(EmailMessageSchema.ReceivedBy);
        propertySet.Add(EmailMessageSchema.ReceivedRepresenting);
        propertySet.Add(EmailMessageSchema.ReplyTo);
        propertySet.Add(EmailMessageSchema.IsResponseRequested);

Заранее благодарим за помощь

ОБНОВЛЕНИЕ

Добавление этих строк в код,я смог выделить ошибку.

if (item.Result != ServiceResult.Success)
            {
                Console.WriteLine("ERROR CODE: " + item.ErrorCode);
                Console.WriteLine("ERROR DETAILS: " + item.ErrorDetails);
                Console.WriteLine("ERROR MESSAGE: " + item.ErrorMessage);
                Console.WriteLine("ERROR PROPERTIES: " + item.ErrorProperties);
                Console.ReadKey();
            }

это результат:

ERROR CODE: ErrorInternalServerTransientError
ERROR DETAILS: System.Collections.Generic.Dictionary`2[System.String,System.String]
ERROR MESSAGE: An internal server error occurred. Try again later.
ERROR PROPERTIES: System.Collections.ObjectModel.Collection`1[Microsoft.Exchange.WebServices.Data.PropertyDefinitionBase]

ОБНОВЛЕНИЕ С ВРЕМЕННЫМ РЕШЕНИЕМ

EmailMessage message;
if (item.Result == ServiceResult.Success)
{
     message = (EmailMessage)item.Item;
}
else
{
     message = EmailMessage.Bind(service, ids[index],propertySet);
}

Когда я сталкиваюсь с неправильным идентификатором, яПросто свяжу это.Информация извлекается правильно, и тогда у меня нет потерянных данных

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