我正在尝试升级使用WebDAV对Exchange 2003的应用程序来返回responseXML,然后在SalesForce CRM上创建案例(使用Web服务wsdl)并将电子邮件中的附件放在案例上。
我们正在转向Exchange 2010 SP2,因此我需要使用EWS访问收件箱。
我收到 ServiceResponseException 错误“在商店中找不到指定的对象。”
这是我的代码:
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);// .Exchange2007_SP1);
List<SearchFilter> searchFilterCollection = new List<SearchFilter>();
searchFilterCollection.Add(new SearchFilter.SearchFilterCollection(LogicalOperator.And, new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false)));
searchFilterCollection.Add(new SearchFilter.SearchFilterCollection(LogicalOperator.And, new SearchFilter.IsEqualTo(EmailMessageSchema.HasAttachments,true)));
SearchFilter searchFilter = new SearchFilter.SearchFilterCollection(LogicalOperator.Or, searchFilterCollection.ToArray());
//creates an object that will represent the desired mailbox
Mailbox mb = new Mailbox(@"bbtest@domain");
ItemView view = new ItemView(1);
//creates a folder object that will point to inbox folder
FolderId fid = new FolderId(WellKnownFolderName.Inbox, mb);
service.Url = new Uri("https://domain/EWS/Exchange.asmx");
//this will bind the mailbox you're looking for using your service instance
Microsoft.Exchange.WebServices.Data.Folder inbox = Microsoft.Exchange.WebServices.Data.Folder.Bind(service, fid);
FindItemsResults<Item> results = service.FindItems(WellKnownFolderName.Inbox, searchFilter, view);
foreach (EmailMessage email in results)
{
Debug.Print(email.From.ToString());
Debug.Print(email.DisplayTo);
Debug.Print(email.Subject);
}
它会在此行引发错误:
Microsoft.Exchange.WebServices.Data.Folder inbox = Microsoft.Exchange.WebServices.Data.Folder.Bind(service, fid);
我做错了什么,我该如何解决?
另外,有没有办法让EWS返回与webDAV类似的XML responseStream?
答案 0 :(得分:7)
根据我的经验,当您无权访问Exchange存储中的对象时,可以返回 NotFound 。确保您使用的任何凭据都具有对目标MB的完全邮箱访问权限。 (我想如果你想要做的只是阅读项目,你可能需要更少的权限,但如果需要你可以稍后修剪。)我没有看到你在上面设置任何凭据,所以你可能正在访问EWS使用您的默认信用卡,即您在运行时记录的内容。
不,你不能从EWS获得WebDAV响应流:它们是完全不同的服务,而且我相信你知道,在E2007之后WebDAV不存在。