Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EWS - Renew subscription after timeout?

This may be a very basic problem, but I haven't found any answer for it yet. I'm using Exchange Web Services in a Windows service to monitor new mails sent to our Exchange 2010 server with a pull subscription. It's working all fine and dandy, but the problems is if the server is not available (such as after a power outage), then the subscription times out, and the Windows service needs to be restarted. Is there a way to renew the subscription after a timeout, or to pull EvenType.Status events?

Here's my code so far:

    ExchangeService service;
    PullSubscription subscriptionInbox;

    private void SetService()
    {
        service = new ExchangeService(ExchangeVersion.Exchange2010);
        service.Url = new Uri("myurl");
        service.Credentials = new WebCredentials(emailAddress, pass);
    }

    private void SetSubscription()
    {
        if (service == null)
        {
            SetService();
        }

        subscriptionInbox = service.SubscribeToPullNotifications(
        new FolderId[] { WellKnownFolderName.Inbox },
        5,
        null,
        EventType.NewMail, EventType.Modified);
    }

    private void DoStuff(object sender, EventArgs e)
    {
        GetEventsResults eventsInbox = subscriptionInbox.GetEvents();
        EmailMessage message;

        foreach (ItemEvent itemEvent in eventsInbox.ItemEvents)
        {
             //Do Stuff
        }
    }

Any ideas how I could go on with this?

like image 798
tamasgobesz Avatar asked Oct 20 '22 23:10

tamasgobesz


1 Answers

When you lose a subscription, it's best to create a new subscription - and not try to recover the interim data. You can resubscribe with the old watermark, but it's cost prohibitive. This link provides some additional context about recovering notifications related to lost subscriptions: http://msdn.microsoft.com/en-us/library/office/dn458788(v=exchg.150).aspx#bk_recover. You may also want to view this Channel 9 video, which discusses recovery from lost subscriptions: http://channel9.msdn.com/Events/Open-Specifications-Plugfests/Windows-Identity-and-Exchange-Protocols-Plugfest-2012/Exchange-Web-Services-Best-Practices-Part-2.

like image 181
Mimi Gentz Avatar answered Oct 23 '22 18:10

Mimi Gentz