Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Azure by (45.3k points)

When you are using the brokered message in the Azure Service Bus, you can retrieve the body of the message with the call .GetBody. The code is simple:

var msg = subscription.Receive();

MyPayload payload = msg.GetBody<MyPayload>();

However, is there a way to retrieve the Body without explicitly knowing the class of the body object?

var msg = subscription.Receive();

Type bodyType = Type.GetType( msg.ContentType);

var payload = msg.GetBody<bodyType>();

1 Answer

0 votes
by (16.8k points)

If the intent is to only grab the message body regardless of the content you can get it as a stream:

Stream stream = message.GetBody<Stream>();

StreamReader reader = new StreamReader(stream);

string s = reader.ReadToEnd();

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.1k users

Browse Categories

...