none
EWS 1.1 - Lost subscription problem RRS feed

  • Question

  • Hi guys.

    I have this piece of code to wait for new mails arriving:

    Imports System.Management
    Imports Microsoft.Exchange.WebServices.Data
    
    Module Module1
        Private subscriptionInbox As PullSubscription
        Private Service As ExchangeService = Nothing
    
        Public Sub Main()
            While 1
                GetLatestMessages()
                Console.WriteLine("Sleeping now...{0}", Now.ToString)
                System.Threading.Thread.Sleep(10000)
            End While
        End Sub 'Main
    
        Private Sub SetService()
            Service.ImpersonatedUserId = New ImpersonatedUserId(ConnectingIdType.SmtpAddress, "Mail2Check4@MyDomain.com")
            Service.AutodiscoverUrl("Mail2Check4@MyDomain.com")
            'Service.Url = New Uri("https://MyWebmailServer.mydomain.com/EWS/Exchange.asmx")
        End Sub
    
        Public Sub SetSubscription()
            If IsNothing(Service) Then
                Service = New ExchangeService(ExchangeVersion.Exchange2007_SP1)
                SetService()
            End If
            '// Subscribe to pull notifications in the Inbox folder, and get notified when
            '// a new mail is received, when an item or folder is created, or when an item
            '// or folder is deleted. 
            subscriptionInbox = service.SubscribeToPullNotifications(New FolderId() {WellKnownFolderName.Inbox}, 5, Nothing, EventType.NewMail)
        End Sub
    
        Private Sub GetLatestMessages()
            If IsNothing(subscriptionInbox) Then
                SetSubscription()
            End If
            Dim eventsInbox As GetEventsResults = subscriptionInbox.GetEvents()
            Dim message As EmailMessage
            '// Loop through all item-related events.
            For Each itemEvent As ItemEvent In eventsInbox.ItemEvents
                If itemEvent.EventType = EventType.NewMail Then
                    Try
                        Dim item As Item = item.Bind(service, itemEvent.ItemId)
                        If item.ItemClass.ToLower() = "IPM.Note".ToLower() Then
                            message = EmailMessage.Bind(service, itemEvent.ItemId)
                            Console.WriteLine("Inbox/NewMail - " + message.Subject)
                        End If
                    Catch Ex As Exception
                        Console.WriteLine("EventType.NewMail - " & itemEvent.ItemId.ToString)
                    End Try
                End If
            Next
        End Sub
    End Module

    My problem is that in a random time after i start the program, it closes with an exception:

    Unhandled Exception: Microsoft.Exchange.WebServices.Data.ServiceResponseException: The specified subscription was not found.
       at Microsoft.Exchange.WebServices.Data.ServiceResponse.InternalThrowIfNecessary()
       at Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest`1.Execute()
       at Microsoft.Exchange.WebServices.Data.ExchangeService.GetEvents(String subscriptionId, String watermark)
       at Microsoft.Exchange.WebServices.Data.PullSubscription.GetEvents()
       at ConsoleApplication1.Module1.GetLatestMessages() in x:\Testing\Module1.vb:line 35
       at ConsoleApplication1.Module1.Main() in x:\Testing\Module1.vb:line 10

    For an unknown reason, the subscription lost after a couple of minutes.

    As a catch routine, I've tried to "resuscript" to the service, but i don't like that solution.

    Ideas?
     

    Monday, January 16, 2012 2:21 PM

All replies

  • I have the same problem and the same solution. 

     

    Chris

    Wednesday, January 18, 2012 2:26 PM
  • Do you have several client access servers? I think nlb-clustered ca servers can not handle push notifications, push subscriptions are only one servers memory.

     


    hvk
    Wednesday, January 25, 2012 11:52 AM
  • Hi all,

    I'm using Streaming Notification with an exchange mailbox in Office 365 and experiencing the same issue...

    When connection timout elapses and the "OnDisconnect" event is fired I try the following:

    StreamingSubscriptionConnection connection = (StreamingSubscriptionConnection)sender;
    connection.Open();

    ...but get the following Exception: "The specified subscription was not found." => "You must add at least one subscription to this connection before it can be opened."

    Seems that the subscription information are lost on the client access server...?!

    Isn't there a workaround for this issue?

    @Harri Kylliäinen
    the nlb concerns seem to be solved with version 1.1 of EWS Managed API: Clients that use the EWS Managed API 1.1 and the EWS Java API 1.1 do not have to manage the exchangecookie cookie as this is done automatically

    http://blogs.msdn.com/b/exchangedev/archive/2011/07/20/client-access-server-affinity-and-network-load-balancing-considerations-for-programmatic-access-to-exchange-online.aspx

    Wednesday, February 8, 2012 9:50 AM