Export (0) Print
Expand All

SubscribeType Class

The SubscribeType class represents a request to subscribe to notifications of events on mailboxes in the Exchange database.

Namespace:  ExchangeWebServices
Assembly:  EWS (in EWS.dll)

[SerializableAttribute]
public class SubscribeType : BaseRequestType

The SubscribeType class is used for both push and pull notification types.

The following code example shows you how to create a pull notification subscription that monitors the Inbox and another folder. The

Inbox is identified by the DistinguishedFolderIdType class and the other folder is identified by the FolderIdType class. Both folders are monitored for new e-mail messages, copied items, moved items, modified items, created items, and deleted items. The subscription will time out only if a GetEvents call is not made within the time-out interval.

static void Subscribe(ExchangeServiceBinding esb)
{
    // Create the request.
    SubscribeType request = new SubscribeType();

    // Identify the type of subscription.
    PullSubscriptionRequestType pullSub = new PullSubscriptionRequestType();

    // Identify the folders that are monitored for events.
    DistinguishedFolderIdType inbox = new DistinguishedFolderIdType();
    inbox.Id = DistinguishedFolderIdNameType.inbox;
    FolderIdType customFolder = new FolderIdType();
    customFolder.Id = "AQAlAE1=";
    pullSub.FolderIds = new BaseFolderIdType[2] { inbox, customFolder };

    // Identify the events that are monitored for the subscription.
    pullSub.EventTypes = new NotificationEventTypeType[6]
    {
        NotificationEventTypeType.CopiedEvent,
        NotificationEventTypeType.CreatedEvent,
        NotificationEventTypeType.DeletedEvent,
        NotificationEventTypeType.ModifiedEvent,
        NotificationEventTypeType.MovedEvent,
        NotificationEventTypeType.NewMailEvent
    };

    // Define the time-out period for the subscription (in minutes).
    pullSub.Timeout = 10;

    request.Item = pullSub;

    // Send the request and get the response.
    SubscribeResponseType response = esb.Subscribe(request);

    ArrayOfResponseMessagesType aormt = response.ResponseMessages;
    ResponseMessageType[] rmta = aormt.Items;

    foreach (ResponseMessageType rmt in rmta)
    {
        // Cast to the appropriate response.
        SubscribeResponseMessageType respMsg = (rmt as SubscribeResponseMessageType);
        
        // Get the new subscription information.
        if (respMsg.ResponseClass == ResponseClassType.Success)
        {
            Console.WriteLine("New subscription: " + respMsg.SubscriptionId);
            Console.WriteLine("Watermark: " + respMsg.Watermark);
        }
    }
}

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft