![](/img/trans.png)
[英]C# EWS ExchangeService: How do I know if it's authenticated?
[英]EWS C# ExchangeService.MoveItems Issue
我遇到了EWS MoveItems问题,希望有人可以帮助我。 在已发送文件夹中有1300封电子邮件后,我调用MoveItems方法将它们全部移到备份文件夹中,并且只有一部分项目被移动! 为了寻找一种模式,我记录了以下测试编号:
测试1:初始计数:1300; 实际##:722
测试2:初始计数:1300; 实际##:661
测试#3:初始计数:1300; 实际##:738
对于每个测试用例,我的日志记录输出均显示已找到1300,并将其传递给MoveItems方法,但是,检查“已发送邮件”文件夹显示并非所有1300都已移动(如上述测试所示)。
这是我的代码片段:
...
do
{
ItemView view = new ItemView(pageSize, offset);
findResults = service.FindItems(folder, emailFilter, view);
Logger.Write("Email count on this page to be archived: " + findResults.Items.Count);
foreach (Item email in findResults)
{
itemIds.Add(email.Id);
}
offset += pageSize;
}
while (findResults.MoreAvailable);
Logger.Write("Total email Ids to be archived: " + itemIds.Count());
if (itemIds.Count() > 0)
{
Logger.Write("Archiving emails...");
service.MoveItems(itemIds, folder5.Folders[0].Id);
Logger.Write("Archive call complete.");
}
else
{
Logger.Write("No emails found to archive.");
}
...
所有这些都包装在try / catch块中。 没有发现错误。
唯一值得注意的其他项目是“归档电子邮件...”日志和“归档呼叫完成”之间的时间。 总是在1分钟内的一两秒钟之内。 可能表示通话超时? 这是我的日志片段:
8/15/2014 4:29:43 PM - Information - Archiving emails...
8/15/2014 4:29:44 PM - Information - Creating search filters...
8/15/2014 4:29:48 PM - Information - Email count on this page to be archived: 1000
8/15/2014 4:29:49 PM - Information - Email count on this page to be archived: 300
8/15/2014 4:29:49 PM - Information - Total email Ids to be archived: 1300
8/15/2014 4:29:49 PM - Information - Archiving emails...
8/15/2014 4:30:51 PM - Information - Archive call complete.
8/15/2014 4:30:51 PM - Information - Email archival completed without errors
我几乎束手无策了,因此,我感谢您可能提供的任何帮助。
在使用EWS时,我遇到了同样的问题。 我不确定“正确”的解决方案是什么,但是我的解决方法似乎可行。 我分析了这一举动,一次移动几百个物品似乎做得不错。 尝试在每次调用MoveItems时移动〜250。
您应该尝试处理运行MoveItems方法时返回的ServiceResponses,例如
if (itemIds.Count() > 0)
{
ServiceResponseCollection<MoveCopyItemResponse> Responses = service.MoveItems(itemIds, folder5.Id);
Int32 Success = 0;
Int32 Error = 0;
foreach (MoveCopyItemResponse respItem in Responses) {
switch (respItem.Result) {
case ServiceResult.Success: Success++;
break;
case ServiceResult.Error: Error++;
Console.WriteLine("Error with Item " + respItem.ErrorMessage);
break;
}
}
Console.WriteLine("Results Processed " + itemIds.Count + " Success " + Success + " Failed " + Error);
}
这将告诉您发生了什么,以及为什么某些动作失败了。 我怀疑它会节流,因此克里斯建议您减小批量大小。 过去,当我写一些东西在Mailbox和Archive之间做大动作时,我批量处理了100个项目,从没遇到问题。 当我将批处理大小设置得太大时,我会看到超时和油门错误。
干杯格伦
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.