Send and receive JSON formatted message with BizTalk Server

BizTalk does not send messages natively in JSON format. However, in recent years, JSON has become the format increasingly widespread.

In order to better use the messaging services of BizTalk limiting as much as possible customizations, normally I use the custom pipeline components for both send and receive operations.

The receive statement is very simple since it is sufficient build a pipeline component that converts JSON formatted message into xml and set a target namespace.

The send statement is slightly more complex because you need to instruct the JSON converter for xml nodes of multiplicity greater than one.

This allows you to correctly generate the JSON array.

To do that, you need work inside the schema, where in any element with multiplicity greater than one, you must specify the attribute json:array equal to true.


We begin by constructing a schema that defines the namespace attribute in JSON.









  <xs:attributename=Arraytype=xs:boolean />




Once built, you must import it.




Following the XML result.




Then you can define the attribute as JSON array.




Defined the schema, you have to implement the send pipeline component. Below is a code example.



public Microsoft.BizTalk.Message.Interop.IBaseMessage Execute(Microsoft.BizTalk.Component.Interop.IPipelineContext pContext, Microsoft.BizTalk.Message.Interop.IBaseMessage pInMsg)



       if (pInMsg.BodyPart != null)



             XmlDocument xmlMessage = new XmlDocument();



             foreach (XmlAttribute attribute in xmlMessage.DocumentElement.Attributes)


                    if (attribute.Name != “xmlns:json”)






             string jsonMessage = JsonConvert.SerializeXmlNode(xmlMessage, Newtonsoft.Json.Formatting.None, true);


             pInMsg.BodyPart.Data = new MemoryStream(new UTF8Encoding().GetBytes(jsonMessage));




       return pInMsg;



Finally, it is necessary to remove the XML envelope from the WCF layer.




3 thoughts on “Send and receive JSON formatted message with BizTalk Server

  1. Reblogged this on BizTalk On My Mind and commented:
    JSON has become such common practice that it should really be it’s own adapter in BizTalk! Great article on how you can send JSON requests using BizTalk!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s