EWS - renew subscription after timeout?

This may be a very simple problem, but I have not yet found the answer. I use Exchange Web Services in Windows to track new emails sent to our Exchange 2010 server with a pull subscription. It works fine and dandy, but the problem is that the server is unavailable (for example, after a power outage), then the waiting time for the subscription and restart of the Windows service. Is there a way to renew my subscription after a timeout or to display EvenType.Status events?

Here is my code:

    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 continue this?

+4
source share

All Articles