none
BizTalk sending message to Service Bus using SB-Messaging Adapter. Not able to set the ContentType to text/json RRS feed

  • Question

  • Hi,

    A message is received from Azure Service bus subscription into BizTalk using SB-Messaging adapter. A separate property scheme is created to promote all the user defined brokered message property. This message is sent to another Service Bus queue using SB-Messaging Adapter. The send port subscribe the message using a Send port filter (BTS.ReceivePortName).

    When the message is posted to the other service bus queue it correctly get queued with the Message Text, Message Custom Properties, and Message Properties except one attribute within the Message Properties which is ContentType.

    This property (ContentType) within the namespace schemas.microsoft.com/BizTalk/2012/Adapter/BrokeredMessage-properties is promoted using a custom pipeline component (in send pipeline at Encode stage) and it shows a value text/json.

    But when the message is browsed through service bus explorer the content type is shown as application/xml; charset=utf-8. Because of this reason the receiving application is not able to process the message.

    So what additional attributes need to be set/taken care to ensure that the ContentType is set to show text/json so that the receiving application can process the message?

    Regards

    Ambareesh

    Friday, November 21, 2014 4:34 AM

Answers

  • Then why not try with alternate approach  where you can send the xlang message to function which will serialize  it to json .Some thing like below

    public void ProcessRequestReturnJsonDocument(XLANGMessage message)
    {
    
    XmlDocument xmlDoc = (XmlDocument)message[0].RetrieveAs(typeof(XmlDocument));
    
    string xmlstr = xmlDoc.OuterXml;
    
    
    xml.LoadXml(xmlstr);
    Response.ContentType = "application/json";
    Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(xmlDoc));
    
    }

    • Marked as answer by Angie Xu Friday, December 5, 2014 2:20 AM
    Wednesday, November 26, 2014 7:56 PM

All replies

  • Do you have JSON Encoder Pipeline Component (XML –> JSON) at your encode stage . I think you are missing this component while sending message out of Biztalk
    Saturday, November 22, 2014 5:19 AM
  • Hi Abhishek,

    Thanks for the reply.

    I also tried the JSON Encoder Pipeline Component (XML –> JSON) at the encode stage. But it is still showing as  application/xml; charset=utf-8.

    Regards

    ambareesh


    Monday, November 24, 2014 10:57 AM
  • Then why not try with alternate approach  where you can send the xlang message to function which will serialize  it to json .Some thing like below

    public void ProcessRequestReturnJsonDocument(XLANGMessage message)
    {
    
    XmlDocument xmlDoc = (XmlDocument)message[0].RetrieveAs(typeof(XmlDocument));
    
    string xmlstr = xmlDoc.OuterXml;
    
    
    xml.LoadXml(xmlstr);
    Response.ContentType = "application/json";
    Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(xmlDoc));
    
    }

    • Marked as answer by Angie Xu Friday, December 5, 2014 2:20 AM
    Wednesday, November 26, 2014 7:56 PM
  • The problem remains and I do not want to create orchestrations just for sending json messages to a service bus queue.

    As far as I can understand this is either a bug in the implementation where the ContentType value is not assigned according to the context property or it has something to do with the serializer used by the WcfTransmitter.

    Looking at the Microsoft.BizTalk.Adapter.SBMessaging.SBMessageInspector.BeforeSendRequest the ContentType is missing both from the default value assignment (which is logical since it's not available on the send port properties) and the iteration of context properties (which I suspect is a bug).

    I'll see if I can add something to the WCF pipeline to assign the ContentType but as I said - this is most probably a bug that should be corrected by Microsoft.

    /andreas

    Wednesday, October 23, 2019 8:50 AM