The Service Bus (SB-Messaging) adapter is used to receive and send messages from Service Bus entities such as Queues, Topics, and Relays. You can use the SB-Messaging adapter to connect your on-premises BizTalk Server to Azure.
Today, someone asked me how to set the correct Content-Type when sending a message to the Service Bus from BizTalk Server. Because it was always set to application/xml by default, even though we were sending a CSV file to the Service Bus.

My first answer was, you can set that property in the send port in the Properties tab in the configurations of the Service Bus adapter

And indeed, yes, this is an option. However, the team told me that the ContentType property didn’t exist!

And they also were correct! I was using BizTalk Server 2020, and they were using BizTalk Server 2016 with different configurations. And yes, indeed, it was always set to application/xml by default.
So the main question was: how to properly set the correct Content-Type?
The SB-Messaging adapter provides a set of context properties, specific to SB-Messaging, using the following namespace:
- Namespace: http://schemas.microsoft.com/BizTalk/2012/Adapter/BrokeredMessage-properties
ContentType is one of them, and is a string value that you can configure.
But you can also find others, such as MessageId, Label, LockToken, ReplyTo, SessionId, TimeToLive, and so on.
See more about Service Bus context properties here: Your Guide to BizTalk Message Context Properties whitepaper.
Although the ContentType property was not available in the connector configuration, we can change this behavior in the send pipeline or in the orchestration by promoting the correct value for the ContentType property.
For example, if you use a BizTalk Server orchestration to define your business process and, inside, create a message to be sent to Service Bus, you should define SBMessaging.ContentType in this way:
- In my proof-of-concept, I will receive the following XML message
<ns0:In xmlns:ns0="http://SettingContentTypeServiceBus.SchemaIn">
<ContentType>text/plain</ContentType>
</ns0:In>
- And I have a simple orchestration that receives this message, generates another message as output equal to the inbound message, and sets the Content-Type to the value I define in the message body.
msgOut = msgIn;
msgOut(SBMessaging.ContentType) = msgIn.ContentType;

Now, if you test it and check the Service Bus Queue or Topic Subscription, you will see that the contentType property is correctly set to the value we passed.

If you need to do it inside a custom pipeline component, then you need to set it up like this:
InMsg.Context.Write(
"ContentType",
"http://schemas.microsoft.com/BizTalk/2012/Adapter/BrokeredMessage-properties",
"text/csv"
);
Sample Source Code
You can download the source code from:
You can download the source code from:
How to set the Content-Type when sending message to Service Bus from BizTalk
GitHub
Hope you find this helpful! If you liked the content or found it useful and would like to support me in writing more, consider buying (or helping to buy) a Star Wars Lego set for my son.