I am trying to upgrade an application that uses WebDAV against Exchange 2003 to return a responseXML, then it creates cases on SalesForce CRM (using web service wsdl) and puts the attachments from the emails on the cases.
We are moving to Exchange 2010 SP2 so I need to access the inbox using EWS.
I am getting a ServiceResponseException error "The specified object was not found in the store."
Here is my code:
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);
}
it throws the error on this line:
Microsoft.Exchange.WebServices.Data.Folder inbox = Microsoft.Exchange.WebServices.Data.Folder.Bind(service, fid);
what am I doing wrong and how can I fix this please?
Also, is there no way to get EWS to return similar XML responseStream as webDAV?
In my experience, NotFound can be returned when you do not have permission to access the object in the Exchange store. Make sure that whatever credentials you use had full mailbox access rights to the target MB. (I suppose if all you want to do is read items, you might need fewer permissions, but you can trim later on if needed.) I don't see you setting any credentials in the above, so presumably you are accessing EWS with your default creds, i.e. what you're logged in as when running this.
And no, you cannot get a WebDAV response stream from EWS: they are totally different services, and as I'm sure you're aware, WebDAV does not exist after E2007.