I have created a very simple console application that connects to Azure ServiceBus and sends one message. I tried the latest library from Microsoft (Microsoft.Azure.ServiceBus
) but no matter what I do I just get this error:
No connection could be made because the target machine actively refused it ErrorCode: ConnectionRefused
I have tried exactly the same connection string in Service Bus Explorer and it does work just fine. Moreover I connected without problems using the older library from Microsoft (WindowsAzure.ServiceBus
).
var sender = new MessageSender("endpoint", "topicName");
sender.SendAsync(new Message(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject("test"))));
I tried with .NET Framework 4.6.2 and Core, same exception. I suspect there may be some differences in the default protocol that these libraries use, but I could not figure out that for sure.
P.S. Have tried the example from Microsoft docs but result is still the same exception
The old client supported ConnectivityMode
using TCP, HTTP, HTTPS, and AutoDetect
. ServiceBus Explorer is using AutoDetect
, trying TCP first and then failing over to HTTPS, regardless of the TransportMode
you were using (SBMP or AMQP).
With the new client this has changed. TransportMode
now combines both options and offers Amqp
(AMQP over TCP) or AmqpWebSockets
(AMQP over WebSockets). There's no AutoDetect
mode. You will have to create your clients and specify TransportType
as AmqpWebSockets
to bypass blocked TCP port 5671 and instead use port 443.