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?