[英]Getting Azure Servicebus Queue Error "The argument namespaceConnectionString is null or white space. \r\nParameter name: namespaceConnectionString"
I am facing the issue.我正面临这个问题。 I have created the ServiceBus Queue on Azure portal.我在 Azure 门户上创建了 ServiceBus 队列。 Also I have written the .Net core application for send the data.我还编写了用于发送数据的 .Net 核心应用程序。 When I Send the data to queue from my application then I have got the below error message at the connection string when QueueClient initialize :当我将数据从我的应用程序发送到队列时,当 QueueClient 初始化时,我在连接字符串中收到以下错误消息:
"The argument namespaceConnectionString is null or white space.\\r\\nParameter name: namespaceConnectionString" "参数 namespaceConnectionString 为空或空白。\\r\\n参数名称:namespaceConnectionString"
I have google as well and tried all the options like remove the EntityPath from the connection string.我也有谷歌并尝试了所有选项,例如从连接字符串中删除 EntityPath。 Also tried the different Target Framework version (till 3.1) as well currently using .Net Core 2.2.还尝试了不同的 Target Framework 版本(直到 3.1)以及目前使用 .Net Core 2.2。
Please help me.请帮我。
using AzureTestProject.Interface;
using Microsoft.Azure.ServiceBus;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AzureQueueService
{
public class ServiceBusQueue
{
private QueueClient _queueClient;
private readonly IConfiguration _configuration;
private const string QUEUE_NAME = "devicetestqueue";
private string _connectionString;
// Payload = {"Id":"1","Type":"Device1","SerialNumber":"10001"}
public async Task SendMessage(object payload)
{
try
{
_queueClient = new QueueClient(
_configuration.GetConnectionString("Endpoint=sb://Subscription.servicebus.windows.net/;SharedAccessKeyName=DeviceTestQueueListenAccessKey;SharedAccessKey=hjklgtfapinznyx2gSnPqngQgIa9p7AxeihLoBz8+Sc=;EntityPath=devicetestqueue"),
QUEUE_NAME);
string data = JsonConvert.SerializeObject(payload);
Message message = new Message(Encoding.UTF8.GetBytes(data));
await _queueClient.SendAsync(message);
}
catch (Exception ex)
{
throw;
}
}
}
}
I have got the solution as below :我得到了如下解决方案:
public async Task SendMessage(object payload)
{
try
{
_queueClient = new QueueClient("Endpoint=sb://Subscription.servicebus.windows.net/;SharedAccessKeyName=DeviceTestQueueListenAccessKey;SharedAccessKey=hjklgtfapinznyx2gSnPqngQgIa9p7AxeihLoBz8+Sc=;EntityPath=devicetestqueue", QUEUE_NAME);
string data = JsonConvert.SerializeObject(payload);
Message message = new Message(Encoding.UTF8.GetBytes(data));
await _queueClient.SendAsync(message);
}
catch (Exception ex)
{
throw;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.