本文介绍了无法使用Microsoft.Azure.ServiceBus连接到Azure ServiceBus的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个非常简单的控制台应用程序,该应用程序连接到Azure ServiceBus并发送一条消息。我尝试了Microsoft提供的最新库( Microsoft.Azure.ServiceBus ),但是无论我做什么我都只会收到此错误:

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:

我在Service Bus Explorer中尝试了完全相同的连接字符串,并且确实可以正常工作。此外,我使用Microsoft的旧库( WindowsAzure.ServiceBus )进行连接也没有问题。

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"))));

我尝试使用.NET Framework 4.6.2和Core,但有相同的例外。我怀疑这些库使用的默认协议可能存在一些差异,但是我不能确定这一点。

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。从,但结果仍然是相同的例外

P.S. Have tried the example from Microsoft docs but result is still the same exception

推荐答案

旧客户端支持使用TCP,HTTP,HTTPS和 AutoDetect 。 ServiceBus Explorer使用 AutoDetect ,先尝试TCP,然后故障转移到HTTPS,无论您使用的是 TransportMode ( SBMP或AMQP)。

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).

对于新客户端,这已更改。 TransportMode 现在结合了这两个选项,并提供 Amqp (基于TCP的AMQP)或 AmqpWebSockets (基于WebSocket的AMQP)。没有自动检测模式。您将必须创建您的客户端并将 TransportType 指定为绕过阻止的TCP端口5671,而使用端口443。

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.

这篇关于无法使用Microsoft.Azure.ServiceBus连接到Azure ServiceBus的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 13:09