[Feature Request] Deserialize message sent from WindowsAzure.ServiceBus (Track Zero)
See original GitHub issueWe might want to add an API, sample, or document explaining how to deserialize a message sent from WindowsAzure.ServiceBus
(the “Track 0” SDK). To run the following repro, create a .NET Framework console app (not .NET Core) and add package references to WindowsAzure.ServiceBus
(Track 0) and Azure.Messaging.ServiceBus
(Track 2).
// Send from WindowsAzure.ServiceBus (Track 0)
var factory1 = MessagingFactory.CreateFromConnectionString(connectionString);
var client1 = factory1.CreateQueueClient("test");
client1.Send(new BrokeredMessage("WindowsAzure.ServiceBus"));
// Receive from Azure.Messaging.ServiceBus (Track 2)
var client2 = new ServiceBusClient(connectionString);
var receiver2 = client2.GetReceiver("test");
var message2 = await receiver2.ReceiveAsync();
var body2Bytes = message2.Body.ToArray();
var invalidBody2 = Encoding.UTF8.GetString(body2Bytes);
Console.WriteLine(invalidBody2);
// @strin3http://schemas.microsoft.com/2003/10/Serialization/?WindowsAzure.ServiceBus
var validBody2 = Deserialize<string>(body2Bytes);
Console.WriteLine(validBody2);
// WindowsAzure.ServiceBus
await receiver2.CompleteAsync(message2);
public static T Deserialize<T>(byte[] data)
{
var serializer = new DataContractSerializer(typeof(T));
using (var stream = new MemoryStream(data))
using (var reader = XmlDictionaryReader.CreateBinaryReader(stream, XmlDictionaryReaderQuotas.Max))
{
return (T)serializer.ReadObject(reader);
}
}
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Azure service bus Message deserialize broken in core ...
1 Answer. Message. GetBody<T>() is an extension method for messages sent using the legacy Service Bus SDK (WindowsAzure. ServiceBus package) ...
Read more >Track custom operations with Application Insights .NET SDK
Application Insights SDKs automatically track incoming HTTP requests and calls to dependent services, such as HTTP requests and SQL queries.
Read more >Azure service bus SerializationException due to extra bytes
I'm getting a SerializationException when the consumer tries to deserialize the message envelope: SerializationException: An exception occurred while ...
Read more >Azure ServiceBus Message Serialization/Deserialization
Assume the following class is the type of which object instances will be sent to/received from an Azure Service Bus queue:
Read more >Using Windows Azure Service Bus Messaging.
This article describes consuming Windows Azure Service Bus by WCF and WF Technologies.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
We have a sample for this now - https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/servicebus/Azure.Messaging.ServiceBus/samples/Sample08_Interop.md
For more context, it appears that this issue exists in the track one library as well, where it is worked around by use of two types in the
Extensions
namespace, one of which provides a special serializer and the other which offers an extension method to the message object. These can be seen in the following locations: