If a .NET app still talks to Azure Service Bus through WindowsAzure.ServiceBus or Microsoft.Azure.ServiceBus, it's running on libraries Microsoft no longer supports. If it uses WindowsAzure.ServiceBus with its default SBMP transport, it also depends on a protocol that Microsoft retired on the same day and says can no longer be used, so it has to switch to AMQP. Here is the quick fix and the real one.
Azure.Messaging.ServiceBus, which uses AMQP by default.WindowsAzure.ServiceBus uses SBMP unless you tell it otherwise. Microsoft documents how to run version 2.1 or later over AMQP 1.0 instead: add TransportType=Amqp to the connection string, or set the TransportType option where your code creates its clients. AMQP needs outbound ports 5671 and 5672; if only port 443 is open, use TransportType=AmqpWebSockets.
Endpoint=sb://contoso.servicebus.windows.net/;SharedAccessKeyName=app;SharedAccessKey=...;TransportType=Amqp
Test it before you rely on it: a few features behave differently over AMQP in the old library. This buys time; it doesn't make an unsupported library supported. BizTalk Server 2020 customers: Microsoft's note describes a hotfix (KB5091379, for BizTalk Server 2020 CU6 and CU7, available through a support case or the note's temporary download link) that adds AMQP to the SB-Messaging adapter and makes AMQP its default transport.
| WindowsAzure.ServiceBus | Azure.Messaging.ServiceBus |
|---|---|
MessagingFactory, connection per client | One ServiceBusClient per namespace, kept for the app's lifetime |
QueueClient.Send, TopicClient.Send | ServiceBusSender.SendMessageAsync, or SendMessagesAsync for batches |
QueueClient.OnMessage, SubscriptionClient.OnMessage | ServiceBusProcessor with ProcessMessageAsync and ProcessErrorAsync |
MessageReceiver.Receive | ServiceBusReceiver.ReceiveMessageAsync |
BrokeredMessage.Complete, Abandon, DeadLetter | CompleteMessageAsync, AbandonMessageAsync, DeadLetterMessageAsync on the receiver, or on the event args in a processor |
Sessions: RegisterSessionHandler, AcceptMessageSession | ServiceBusSessionProcessor in place of the session handler; AcceptNextSessionAsync for the next available session, or AcceptSessionAsync for a named one |
NamespaceManager (create queues, topics, rules) | ServiceBusAdministrationClient |
BrokeredMessage | ServiceBusMessage to send, ServiceBusReceivedMessage when received |
Coming from Microsoft.Azure.ServiceBus, the old names differ, but they map to the same new types: Message instead of BrokeredMessage, SendAsync on QueueClient, TopicClient or MessageSender, RegisterMessageHandler instead of OnMessage, MessageReceiver.ReceiveAsync, SessionClient.AcceptMessageSessionAsync or RegisterSessionHandler for sessions, ManagementClient instead of NamespaceManager, and a shared ServiceBusConnection where the new library uses one ServiceBusClient.
new BrokeredMessage(myObject) serializes the object with DataContractSerializer in binary XML. The new library's Body gives you those bytes as they are, so for messages sent by code that hasn't moved yet message.Body.ToString() returns unreadable text and a JSON deserializer throws. While old senders and new receivers run side by side, read those bodies the old way:
var serializer = new DataContractSerializer(typeof(OrderPlaced));
using var reader = XmlDictionaryReader.CreateBinaryReader(
message.Body.ToStream(), XmlDictionaryReaderQuotas.Max);
var order = (OrderPlaced)serializer.ReadObject(reader);
Because Microsoft says SBMP can no longer be used, old senders that still run should already be on AMQP, so strings, numbers, byte arrays and the other types in Microsoft's AMQP type mapping arrive as an AMQP value instead: reading Body throws NotSupportedException, and you read them with message.GetRawAmqpMessage().Body.TryGetValue(out object value). Streams and custom objects still arrive in an AMQP data section, custom objects as DataContractSerializer bytes.
Move receivers first, keep them able to read both formats, then move the senders to an explicit format such as JSON with ContentType set.
WindowsAzure.ServiceBus or Microsoft.Azure.ServiceBus, including Event Hubs code and BizTalk adapters.Azure.Messaging.ServiceBus with the dual-format body reader, then senders.DefaultAzureCredential or a managed identity) while you're there.Azure.Messaging.ServiceBus targets .NET Standard 2.0, so it also runs on .NET Framework: the move doesn't force an upgrade to modern .NET.