在尝试删除特定人员日历上的所有约会时,我首先收到此错误:“超过一次请求中可删除的最多1000个项目”
然后我尝试使用此代码使用最大大小为1000的批次来修复它:
private IEnumerable<IEnumerable<T>> Batch<T>(IEnumerable<T> input, int batchSize)
{
List<T> items = new List<T>();
foreach (var item in input)
{
items.Add(item);
if (items.Count == batchSize)
{
yield return items;
items = new List<T>();
}
}
if (items.Count > 0)
{
yield return items;
}
}
然后使用它:
var batches = Batch(GetAllSafeAppointments(calendar).Select(a => a.Id), 1000);
foreach (var batch in batches)
{
service.DeleteItems(batch, DeleteMode.HardDelete, SendCancellationsMode.SendToNone, null);
}
然后我收到此错误:
Exchange Web服务当前不可用于此请求,因为目标站点中的任何客户端访问服务器都无法处理该请求。 ved Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ProcessWebException(WebException webException)ved Microsoft.Exchange.WebServices.Data.ServiceRequestBase.GetEwsHttpWebResponse(IEwsHttpWebRequest request)ved Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ValidateAndEmitRequest(IEwsHttpWebRequest&amp; request)ved Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest1.Execute() VED Microsoft.Exchange.WebServices.Data.ExchangeService.InternalDeleteItems(IEnumerable1 itemIds,DeleteMode deleteMode,Nullable1 sendCancellationsMode,Nullable1 affectedTaskOccurrences,ServiceErrorHandling ErrorHandling中,布尔suppressReadReceipts)粘弹性阻尼器Microsoft.Exchange.WebServices.Data.ExchangeService.DeleteItems(IEnumerable1 itemIds,DeleteMode deleteMode, Nullable1 sendCancellationsMode,Nullable`1 affectedTaskOccurrences)ved SafeToExchangeSync.SafeScheduleSyncronizer.DeleteAllSafeAppointments(SCDriftConnection conn,ExchangeService service,SAFEAgent agent)i S:\ s0book \ xxx \ xxx \ xxx \ SafeToExchangeSync \ SafeScheduleSyncronizer.cs:linje 151
答案 0 :(得分:1)
当您不使用X-AnchorMailbox标头并访问与该帐户关联的主邮箱之外的邮箱时,通常会发生此错误。最简单的解决方法是将ExchangeService对象上的X-AnchorMailbox设置为您尝试访问的邮箱,例如
service.HttpHeaders.Add("X-AnchorMailbox", "Mailbox@domain.com");
您应始终使用此标头,因为它确保您的请求始终路由到正确的CAS服务器。