C#AWS SQS客户端由于其保护级别而无法访问 [英] C# AWS SQS Client inaccessible due to it's protection level
问题描述
因此,在从AWS上获取示例以使其适用于C#时,我一直遇到问题.我直接从他们的网站下面复制代码,并将其放在我的程序中,但是当它调用client.ListQueues(request);时.它告诉我由于保护级别而无法访问.我已经花了很多时间搜索,但是我无法弄清楚为什么这是行不通的.任何帮助将不胜感激.
So I've been having an issue getting the example from AWS to work for C#. I copy the code below straight from their site and put it in my program, but when it calls client.ListQueues(request); it tells me that it's inaccessible due to it's protection level. I've spent time searching, but I can't figure out why this isn't work. Any help would be appreciated.
var client = new AmazonSQSClient();
// List all queues that start with "aws".
var request = new ListQueuesRequest
{
QueueNamePrefix = "aws"
};
var response = client.ListQueues(request);
var urls = response.QueueUrls;
if (urls.Any())
{
Console.WriteLine("Queue URLs:");
foreach (var url in urls)
{
Console.WriteLine(" " + url);
}
}
else
{
Console.WriteLine("No queues.");
}
推荐答案
在某些平台的文档中可以找到,方法 ListQueues
不可用.文档说:
As it can be found in docs for some platforms the method ListQueues
is not available. The docs says:
对于.NET Core,PCL和Unity,此操作仅以异步形式可用.请参考ListQueuesAsync.
For .NET Core, PCL and Unity this operation is only available in asynchronous form. Please refer to ListQueuesAsync.
因此,您必须使用异步方法 ListQueuesAsync
,并使调用方法为asnyc.您的代码应如下所示:
So you have to use the asynchronous method ListQueuesAsync
and make your calling method asnyc. Your code should look like:
public async Task<Result> SomeAction()
{
var client = new AmazonSQSClient();
// List all queues that start with "aws".
var request = new ListQueuesRequest
{
QueueNamePrefix = "aws"
};
var response = await client.ListQueuesAsync(request);
// rest of the code
}
这篇关于C#AWS SQS客户端由于其保护级别而无法访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!