Reputation: 143
Why do I get the exception "The specified object was not found in the store" when I getting created event or notification with in help of pull subscription?
The EWS SOAP Response looks like:
<Trace Tag="EwsResponse" Tid="1" Time="2013-09-27 12:38:43Z" Version="15.00.0516.014">
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Header>
<t:ServerVersionInfo MajorVersion="8" MinorVersion="3" MajorBuildNumber="83" MinorBuildNumber="4" Version="Exchange2007_SP1" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" />
</soap:Header>
<soap:Body>
<m:GetItemResponse xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages">
<m:ResponseMessages>
<m:GetItemResponseMessage ResponseClass="Error">
<m:MessageText>The specified object was not found in the store.</m:MessageText>
<m:ResponseCode>ErrorItemNotFound</m:ResponseCode>
<m:DescriptiveLinkKey>0</m:DescriptiveLinkKey>
<m:Items />
</m:GetItemResponseMessage>
</m:ResponseMessages>
</m:GetItemResponse>
</soap:Body>
This is my code:
PullSubscription subscription = service.SubscribeToPullNotifications(
new FolderId[] { WellKnownFolderName.Inbox }, 1, WaterMark,
EventType.NewMail, EventType.Created, EventType.Moved, EventType.Deleted);
WaterMark = subscription.Watermark;
// Initiate the GetEvents method for the new subscription.
GetEventsResults events = subscription.GetEvents();
// Handle the results of the GetEvents method.
foreach (ItemEvent itemEvent in events.ItemEvents)
{
switch (itemEvent.EventType)
{
case EventType.NewMail:
Console.WriteLine("New Mail");
EmailMessage message = EmailMessage.Bind(service, itemEvent.ItemId);
if (message.Subject.Equals(""))
{
break;
}
Item item = Item.Bind(service, itemEvent.ItemId);
RulesApplied(service, message, item);
break;
case EventType.Created:
Console.WriteLine("Created");
EmailMessage message1 = EmailMessage.Bind(service, itemEvent.ItemId);
// Here I get the Exception.
break;
Upvotes: 2
Views: 7382
Reputation: 1099
I've found this exception is thrown when the message has been moved or deleted by the mailbox owner after the lower watermark was set.
I believe the ItemEvents collection contains the items affected by the subscribed event (e.g. new messages), but not all of the items in the collection may still be relevant - e.g. the ItemId is no longer valid because it's been affected by a later event like a delete.
You may find that more frequent polling can catch the item before the end user has touched the message, however in an application within my organisation, we just log the exception as the mailbox user likely has a specific reason to move or delete the message before the subscribed app acted on the message event.
Upvotes: 5