AWS SDK Version 2 for .NET
API Reference

AWS services or capabilities described in AWS Documentation may vary by region/location. Click Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.

.NET Framework 4.5
 
Container for the parameters to the Subscribe operation. Prepares to subscribe an endpoint by sending the endpoint a confirmation message. To actually create a subscription, the endpoint owner must call the ConfirmSubscription action with the token from the confirmation message. Confirmation tokens are valid for three days.

Inheritance Hierarchy

System.Object
  Amazon.Runtime.AmazonWebServiceRequest
    Amazon.SimpleNotificationService.AmazonSimpleNotificationServiceRequest
      Amazon.SimpleNotificationService.Model.SubscribeRequest

Namespace: Amazon.SimpleNotificationService.Model
Assembly: AWSSDK.dll
Version: (assembly version)

Syntax

C#
public class SubscribeRequest : AmazonSimpleNotificationServiceRequest
         IRequestEvents

The SubscribeRequest type exposes the following members

Constructors

NameDescription
Public Method SubscribeRequest() Empty constructor used to set properties independently even when a simple constructor is available
Public Method SubscribeRequest(string, string, string) Instantiates SubscribeRequest with the parameterized properties

Properties

NameTypeDescription
Public Property Endpoint System.String Gets and sets the property Endpoint.

The endpoint that you want to receive notifications. Endpoints vary by protocol:

  • For the http protocol, the endpoint is an URL beginning with "http://"
  • For the https protocol, the endpoint is a URL beginning with "https://"
  • For the email protocol, the endpoint is an email address
  • For the email-json protocol, the endpoint is an email address
  • For the sms protocol, the endpoint is a phone number of an SMS-enabled device
  • For the sqs protocol, the endpoint is the ARN of an Amazon SQS queue
  • For the application protocol, the endpoint is the EndpointArn of a mobile app and device.
Public Property Protocol System.String Gets and sets the property Protocol.

The protocol you want to use. Supported protocols include:

  • http -- delivery of JSON-encoded message via HTTP POST
  • https -- delivery of JSON-encoded message via HTTPS POST
  • email -- delivery of message via SMTP
  • email-json -- delivery of JSON-encoded message via SMTP
  • sms -- delivery of message via SMS
  • sqs -- delivery of JSON-encoded message to an Amazon SQS queue
  • application -- delivery of JSON-encoded message to an EndpointArn for a mobile app and device.
Public Property TopicArn System.String Gets and sets the property TopicArn.

The ARN of the topic you want to subscribe to.

Examples

This example shows how to create, subscribe to, and publish a topic.

Create, subscribe to, and publish topic example

var snsClient = new AmazonSimpleNotificationServiceClient();

var topicRequest = new CreateTopicRequest
{
  Name = "CodingTestResults"
};

var topicResponse = snsClient.CreateTopic(topicRequest);

var topicAttrRequest = new SetTopicAttributesRequest
{
  TopicArn = topicResponse.TopicArn,
  AttributeName = "DisplayName",
  AttributeValue = "Coding Test Results"
};

snsClient.SetTopicAttributes(topicAttrRequest);

snsClient.Subscribe(new SubscribeRequest
{
  Endpoint = "johndoe@example.com",
  Protocol = "email",
  TopicArn = topicResponse.TopicArn
});

// Wait for up to 2 minutes for the user to confirm the subscription.
DateTime latest = DateTime.Now + TimeSpan.FromMinutes(2);

while (DateTime.Now < latest)
{
  var subsRequest = new ListSubscriptionsByTopicRequest
  {
    TopicArn = topicResponse.TopicArn
  };

  var subs = snsClient.ListSubscriptionsByTopic(subsRequest).Subscriptions;

  var sub = subs[0];

  if (!string.Equals(sub.SubscriptionArn,
    "PendingConfirmation", StringComparison.Ordinal))
  {
    break;
  }

  // Wait 15 seconds before trying again.
  System.Threading.Thread.Sleep(TimeSpan.FromSeconds(15));
}

snsClient.Publish(new PublishRequest
{
  Subject = "Coding Test Results for " +
    DateTime.Today.ToShortDateString(),
  Message = "All of today's coding tests passed.",
  TopicArn = topicResponse.TopicArn
});
      

Version Information

.NET Framework:
Supported in: 4.5, 4.0, 3.5

.NET for Windows Store apps:
Supported in: Windows 8.1, Windows 8

.NET for Windows Phone:
Supported in: Windows Phone 8.1, Windows Phone 8