Partager via


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)

Syntax

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

Remarks

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

Inheritance Hierarchy

System.Object
   ExchangeWebServices.BaseRequestType
    ExchangeWebServices.SubscribeType

Example

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

Thread Safety

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

Platforms

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)