删除附件时出现Exchange错误

问题描述 投票:1回答:1

我正在维护一个服务,用于与EWS(ExchangeWebService)同步联系人。此服务正在更新最近停止工作的contactpictures。抛出的异常是DeleteAttachmentException

最初代码看起来像这样:

contact.SetContactPicture(filePath);
contact.Update(ConflictResolutionMode.AlwaysOverwrite); // throws the excpetion

即使它只是“覆盖”联系人图片,似乎旧的内容首先被内部删除,因此我猜错误消息。

所以我试图先手动确定删除,这也不是一个解决方案:

if(contact.HasPicture)
{
    contact.RemoveContactPicture();
    contact.Update(ConflictResolutionMode.AlwaysOverwrite); // throws the Exception
}

创建新联系人时,这很好。它显示Contactpicture。但是,现有的更新不起作用。

遗憾的是,例外并未提供太多信息:

Microsoft.Exchange.WebServices.Data.DeleteAttachmentException ist aufgetreten.
  _HResult=-2146233088
  _message=At least one attachment couldn't be deleted.
  HResult=-2146233088
  IsTransient=false
  Message=At least one attachment couldn't be deleted.
  Source=Microsoft.Exchange.WebServices
  StackTrace:
  Microsoft.Exchange.WebServices.Data.AttachmentCollection.InternalDeleteAttachments(IEnumerable`1 attachments)
InnerException: 

整个事情在usercontext(邮箱的所有者)中运行。

UPDATE

无论附件是联系人图片还是其他任何相同的结果,我都完全独立了:

_item是一个ExchangeItem(已加载)

public void UpdateAttachment(string attachmentPath, string attachmentName)
{
    Attachment attachment = _item.Attachments.SingleOrDefault(att => String.Equals(att.Name, attachmentName, StringComparison.OrdinalCultureIgnoreCase));

    if (attachment != null)
    {
        _item.Attachments.Remove(attachment);
        _item.Update(ConflictResolutionMode.AlwaysOverwrite);
    }

    attachment = _item.Attachments.AddFileAttachment(attachmentName, attachmentPath);

    _item.Update(ConflictResolutionMode.AlwaysOverwrite);
}
c# web-services exchange-server exchangewebservices
1个回答
1
投票

您是正确的,EWS托管API在保存新附件之前会在内部删除旧附件。您收到的错误是由于服务的通信问题。如果您的代码之前正在运行,我猜测有关运行此代码的用户的权限已发生变化。

所以我建议你检查的第一件事是用户的权限。其次,如果这不能解决您的问题,我建议您在代码中添加一个跟踪侦听器并发布您的EWS请求和响应,以便我们可以进一步跟踪它。这篇文章应该可以帮助您跟踪跟踪器:

How to: Trace requests and responses to troubleshoot EWS Managed API applications

我希望这有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.