Amazon简单通知服务AWSSDK C# - SOS [英] Amazon Simple Notification Service AWSSDK C# - S.O.S

查看:904
本文介绍了Amazon简单通知服务AWSSDK C# - SOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想发布与亚马逊的AWSSDK的C#和简单通知服务。

有没有样品附带的SDK,也没有样本在网络上的任何地方我能找到2小时谷歌搜索后。我想出了这一点,但它抛出一个异常,能产生不超过一个字符串,TopicARN的详细信息 - 没有内部异常 - !nuffin
如果有人通过C#中使用成功发送一个消息 SNS AWSSDK 我很想看到,即使是最起码的工作示例。我使用的是最新的SDK 1.5倍

这里的code:

 字符串资源名称=ARN:AWS:SNS:美国东部-1:XXXXXXXXXXXX:StackOverFlowStub;
AmazonSimpleNotificationServiceClient snsclient =新AmazonSimpleNotificationServiceClient(ACCESSKEY,SecretKey的);
AddPermissionRequest permissionRequest =新AddPermissionRequest()
                .WithActionNames(发布)
                .WithActionNames(ACCESSKEY)
                .WithActionNames(PrincipleAllowControl)
                .WithActionNames(资源名称);
snsclient.AddPermission(permissionRequest);

PublishRequest PR =新PublishRequest();
pr.WithMessage(测试消息);
pr.WithTopicArn(资源名称);
pr.WithSubject(测试对象);
snsclient.Publish(PR);
 

解决方案

下面是创建一个主题,设置一个主题的显示名称,认购的电子邮件地址的话题,发送一条消息,并删除主题的样本。请注意,有两个点,你应该等待/继续之前检查你的电子邮件。 客户端是客户机实例, topicName 是一个任意的主题名称。

  //创建话题
字符串topicArn = client.CreateTopic(新CreateTopicRequest
{
    NAME = topicName
})CreateTopicResult.TopicArn;

//设置显示名称为友好值
client.SetTopicAttributes(新SetTopicAttributesRequest
{
    TopicArn = topicArn,
    AttributeName的=显示名称,
    的AttributeValue =计算器样品通知
});

//订阅端点 - 在这种情况下,电子邮件地址
client.Subscribe(新SubscribeRequest
{
    TopicArn = topicArn,
    协议=电子邮件,
    端点=sample@example.com
});

//当使用电子邮件,收件人必须确认认购
Console.WriteLine(请检查时,你订阅的​​邮件和preSS进入......);
到Console.ReadLine();

//发布消息
client.Publish(新PublishRequest
{
    主题=测试,
    消息=测试测试1 2 3
    TopicArn = topicArn
});

//验证电子邮件receieved
Console.WriteLine(请检查您的电子邮件和preSS,当您收到消息......进入);
到Console.ReadLine();

//删除话题
client.DeleteTopic(新DeleteTopicRequest
{
    TopicArn = topicArn
});
 

I am trying to publish with Amazon's AWSSDK for C# and the Simple Notification Service.

There are no samples that come with the SDK and there are no samples anywhere on the web I could find after 2 hours of Googling. I came up with this but it is throwing an exception that yields no more information than the single string, "TopicARN" - no inner exception - nuffin!
If anyone has successfully sent a message with SNS via C# using the AWSSDK I would love to see even the most rudimentary working example. I am using the latest SDK 1.5x

Here's the code:

string resourceName = "arn:aws:sns:us-east-1:xxxxxxxxxxxx:StackOverFlowStub";
AmazonSimpleNotificationServiceClient snsclient = new AmazonSimpleNotificationServiceClient(accesskey,secretkey);
AddPermissionRequest permissionRequest = new AddPermissionRequest()
                .WithActionNames("Publish")
                .WithActionNames(accesskey)
                .WithActionNames("PrincipleAllowControl")
                .WithActionNames(resourceName);
snsclient.AddPermission(permissionRequest);

PublishRequest pr = new PublishRequest();
pr.WithMessage("Test Msg");
pr.WithTopicArn(resourceName);
pr.WithSubject("Test Subject");
snsclient.Publish(pr);

解决方案

Here is a sample that creates a topic, sets a topic display name, subscribes an email address to the topic, sends a message and deletes the topic. Note that there are two spots where you should wait/check your email before continuing. Client is the client instance, topicName is an arbitrary topic name.

// Create topic
string topicArn = client.CreateTopic(new CreateTopicRequest
{
    Name = topicName
}).CreateTopicResult.TopicArn;

// Set display name to a friendly value
client.SetTopicAttributes(new SetTopicAttributesRequest
{
    TopicArn = topicArn,
    AttributeName = "DisplayName",
    AttributeValue = "StackOverflow Sample Notifications"
});

// Subscribe an endpoint - in this case, an email address
client.Subscribe(new SubscribeRequest
{
    TopicArn = topicArn,
    Protocol = "email",
    Endpoint = "sample@example.com"
});

// When using email, recipient must confirm subscription
Console.WriteLine("Please check your email and press enter when you are subscribed...");
Console.ReadLine();

// Publish message
client.Publish(new PublishRequest
{
    Subject = "Test",
    Message = "Testing testing 1 2 3",
    TopicArn = topicArn
});

// Verify email receieved
Console.WriteLine("Please check your email and press enter when you receive the message...");
Console.ReadLine();

// Delete topic
client.DeleteTopic(new DeleteTopicRequest
{
    TopicArn = topicArn
});

这篇关于Amazon简单通知服务AWSSDK C# - SOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆