Edit

Share via


SubscribeType Class

Definition

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

public ref class SubscribeType : ExchangeWebServices::BaseRequestType
public class SubscribeType : ExchangeWebServices.BaseRequestType
Public Class SubscribeType
Inherits BaseRequestType
Inheritance
SubscribeType

Examples

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 <span class="label">request</span> = 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;

<span class="label">request</span>.Item = pullSub;

    // Send the request and get the response.
    SubscribeResponseType response = esb.Subscribe(<span class="label">request</span>);

    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);
        }
    }
}

Remarks

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

Constructors

SubscribeType()

The SubscribeType constructor initializes a new instance of the SubscribeType class.

Properties

Item

The Item property gets or sets the subscription type. This property gets or sets either a PullSubscriptionRequestType or PushSubscriptionRequestType object. This property is required. This is a read/write property.

Applies to