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] 
[DebuggerStepThroughAttribute] 
[XmlTypeAttribute(Namespace="http://schemas.microsoft.com/exchange/services/2006/messages")] 
[GeneratedCodeAttribute("wsdl", "2.0.50727.42")] 
[DesignerCategoryAttribute("code")] 
public class SubscribeType : BaseRequestType
/** @attribute SerializableAttribute() */ 
/** @attribute DebuggerStepThroughAttribute() */ 
/** @attribute XmlTypeAttribute(Namespace="http://schemas.microsoft.com/exchange/services/2006/messages") */ 
/** @attribute GeneratedCodeAttribute("wsdl", "2.0.50727.42") */ 
/** @attribute DesignerCategoryAttribute("code") */ 
public class SubscribeType extends BaseRequestType
SerializableAttribute 
DebuggerStepThroughAttribute 
XmlTypeAttribute(Namespace="http://schemas.microsoft.com/exchange/services/2006/messages") 
GeneratedCodeAttribute("wsdl", "2.0.50727.42") 
DesignerCategoryAttribute("code") 
public class SubscribeType extends BaseRequestType

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


System.Object
   ExchangeWebServices.BaseRequestType
    ExchangeWebServices.SubscribeType

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.

Development Platforms

Windows XP Professional with Service Pack 2 (SP2), Windows Server 2003,

Target Platforms

Windows 98, Windows 2000, Windows 2000 Server, Windows CE, Windows Longhorn, Windows 98 Second Edition, Pocket PC, Smart Phone, Windows Server 2003, Windows XP Professional with Service Pack 2 (SP2)
Show:
© 2014 Microsoft