none
Not getting in message content into the string in custom pipeline RRS feed

  • Question

  • Hi All,

    I want to get in message into a string. I am trying to get it into custom pipeline through following code:

                            IBaseMessagePart bodyPart = inmsg.BodyPart;
                            Stream originalStream = bodyPart.GetOriginalDataStream();

                            String originalString = originalStream.ToString();

    But i can see that i am not able to get the message part into the originalString but instead of that i am getting below thing into the originalString variable instead of message content:

    "Microsoft.BizTalk.Message.Interop.StreamViewOfIStream"

    Can anyone please suggest me how to get the original content of in message into the originalString variable?????

    Thanks in advance for your support. :) 

    Thursday, June 16, 2016 10:53 AM

Answers

  • Hi 

    Try this instead-

    IBaseMessagePart bodyPart = inmsg.BodyPart;
    Stream originalStream = bodyPart.GetOriginalDataStream();
    byte[] input = new byte[originalStream.Length];
    originalStream.Read(input, 0, (Int32)originalStream.Length);
    string originalMessage = System.Text.Encoding.UTF8.GetString(input);


    Thanks Arindam




    Thursday, June 16, 2016 11:00 AM
    Moderator

All replies

  • Hi 

    Try this instead-

    IBaseMessagePart bodyPart = inmsg.BodyPart;
    Stream originalStream = bodyPart.GetOriginalDataStream();
    byte[] input = new byte[originalStream.Length];
    originalStream.Read(input, 0, (Int32)originalStream.Length);
    string originalMessage = System.Text.Encoding.UTF8.GetString(input);


    Thanks Arindam




    Thursday, June 16, 2016 11:00 AM
    Moderator
  • Following is the method which you can directly use in your pipeline component for Getting String data from message.

    Return string message from IBaseMessage

     public string ReadEntireBody(IBaseMessage msg)
            {
                int BufferSize = 0x280; //  TODO move to external config
                int ThresholdSize = 0x100000;   //  TODO move to external config
                string body = null;
                IBaseMessagePart bodyPart = msg.BodyPart;
                Stream inboundStream = bodyPart.GetOriginalDataStream();
                var virtualStream = new VirtualStream(BufferSize, ThresholdSize);
                var readOnlySeekableStream = new ReadOnlySeekableStream(inboundStream, virtualStream,
                                                                        BufferSize);
                var sr = new StreamReader(readOnlySeekableStream);
                body = sr.ReadToEnd();
                return body;
            }

    Refer: http://biztalkwarriors.blogspot.in/2013/01/convert-biztalk-messagebodypart-to.html


    Rachit Sikroria (Microsoft Azure MVP)



    Thursday, June 16, 2016 11:00 AM
    Moderator
  • Thanku very much Arindam ..it worked :)
    Thursday, June 16, 2016 12:08 PM