ServiceResponseException: The specified object was not found in the store
Asked Answered
D

1

5

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?

Dachia answered 11/3, 2014 at 16:41 Comment(0)
G
9

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.

Guimar answered 12/3, 2014 at 13:12 Comment(5)
@primary +1 thanks for this, I was kind of hoping I could make my EWS response stream xml look like the return from EWS ( maybe by transforming it?) then I could avoid a lot of re-coding work :)Dachia
I'll look into my credentials, I though I could be a delegate on the target mailbox so could read it, looks like I'll need to set Network credentials...Dachia
Alternatively you can look into impersonation, which seems to be the more favored way to go now. So rather than giving user MYDOM\Phil full access to Room1, the Exchange admin allows MYDOM\Phil to impersonate Room1. This requires setting the ImpersonatedUserId property on the ExchangeService object.Guimar
@Guimar Im having same issue. Do you know how to set the EWS admin user permission to the mailbox that I want to have access?Gittern
There's a way to do this in the Exchange Admin UI: Manage Full Access Rights to the Mailbox. I presume there's a Powershell way to do this, but I don' t recall using that.Guimar

© 2022 - 2024 — McMap. All rights reserved.