c# - 由于保护级别 (C#),无法访问 Amazon SNS client.publish
问题描述
我以前从未使用过 SNS,并且正在使用它来尝试学习如何通过 SNS 发送电子邮件。我在网上找到了这段代码,似乎可以满足我的需要。我已经在浏览器中设置了主题和其他内容,并确认了主题和我打算使用的电子邮件之间的连接。这是代码:
using System;
using System.Linq;
using System.Threading.Tasks;
using Amazon;
using Amazon.SimpleNotificationService;
using Amazon.SimpleNotificationService.Model;
namespace Sns_test
{
class Program
{
static void Main(string[] args)
{
/* Topic ARNs must be in the correct format:
* arn:aws:sns:REGION:ACCOUNT_ID:NAME
*
* where:
* REGION is the region in which the topic is created, such as us-west-2
* ACCOUNT_ID is your (typically) 12-character account ID
* NAME is the name of the topic
*/
string topicArn = "arn:aws:sns:us-east-2:058418336484:MailTest";
string message = "Hello at " + DateTime.Now.ToShortTimeString();
var client = new AmazonSimpleNotificationServiceClient(region: Amazon.RegionEndpoint.USWest2);
var request = new PublishRequest
{
Message = message,
TopicArn = topicArn
};
try
{
var response = client.Publish(request);
Console.WriteLine("Message sent to topic:");
Console.WriteLine(message);
}
catch (Exception ex)
{
Console.WriteLine("Caught exception publishing request:");
Console.WriteLine(ex.Message);
}
}
}
}
问题在于:
try
{
var response = client.Publish(request);
Console.WriteLine("Message sent to topic:");
Console.WriteLine(message);
}
client.Publish(request) 由于其保护级别而无法访问。通常,当我的代码无法访问时,我可以解决这些问题,但是对于内置到库中的方法,我该怎么办?
这是错误消息:[错误消息][1]
任何帮助,将不胜感激 :)
编辑:我设法通过使用 client.PublishAsync 解决了这个问题,但我仍然很好奇为什么 client.Publish 将无法访问。[1]:https ://i.stack.imgur.com/av3fO.png
解决方案
检查文件
https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/SNS/MSNSPublishPublishRequest.html
Note:
For .NET Core this operation is only available in asynchronous form. Please refer to PublishAsync.
推荐阅读
- angular - 如何在角度(CLI 7)中为生成的块文件指定绝对 URL
- html - 响应图像未在预期断点处请求文件
- python - 将时间增量添加到天空时间
- go - reflect.TypeOf 是 *string 并返回 0xc0001ae4a8 - 如何打印
- mysql - 我应该如何在 RDS MySQL 表中存储 s3 文件位置?
- typescript - 如何在打字稿中覆盖合并命名空间中的函数
- javascript - 函数参数类型的 Sphinx-js 警告
- python - 使用 pyPDF2 创建多个列表或字典以保存 PDF 对象?
- php - 如何检查会话是否已启动并重定向用户?
- python - 键盘记录器扩展