none
Issue with edi assembler output stream RRS feed

  • Question

  • I am having a problem with custom pipeline component (in Encode stage) while using it in send pipeline having edi assembler.. Issue is while reading the Length property of  the stream received from an edi assembler stage .

     

    I am getting error : "Length.get not supported". Below was the code which was cauing the error.

     

    originalStream = bodyPart.GetOriginalDataStream();

    originalStream.Read(buffer, 0, Convert.ToInt32(originalStream.Length));

     

    Finally I had to use following method to skip this error...

     

    try

     {

    streamLength = originalStream.Length;

     }

    catch (Exception e)

     {

    streamLength = 32768;

     }

     

    buffer = new byte[Convert.ToInt32(streamLength)];

    int read = 0;

    read = originalStream.Read(buffer, 0, Convert.ToInt32(buffer.Length));

    outBytes = new byte[read];

    Array.Copy(buffer, outBytes, read);

     

    Any idea why .Length method is not supported on an IBaseMessage stream from edi assembler? So far I faced this problem only while using with edi assembler.

    Friday, August 31, 2007 1:45 PM

Answers

  • The length of a stream is non deterministic due to a factors like compression etc, and that is why you see the exception. The only way to determine the length of a stream is to read the whole stream and resetting the position to the start when you are done (which you can see is expensive)

     

    Here's one approach: Create a byte array of fixed length and try reading the stream while filling in the byte array in a while loop. After you are done, just reset the position of the stream to the beginning.

     

    Byte[] b = new Byte[1024];

    Stream str = baseMessage.BodyPart.GetOriginalDataStream();

    int temp;

    int counter = 0;

    while ((temp=str.Read(b, 0, b.Length)) > 0)

    {

    counter+=temp;

    }

     

    When this code exists, counter will contain the length of your original stream.

     

    Please note that this code only shows you how to get the length of the stream. The code to reset is not shown.

     

    Thanks

    Mohsin

     

     

    Wednesday, September 19, 2007 8:44 PM

All replies

  • It's only a guess...
    Maybe they transform the stream in such manner that the Length is unpredictable.
    I have the same issue when construct my custom pipeline component.
     
    Regards,
     
    Leonid Ganeline
     
    Friday, August 31, 2007 3:52 PM
  •  

    just noticed this issue with flat file assembler also..
    Monday, September 17, 2007 12:35 PM
  • The length of a stream is non deterministic due to a factors like compression etc, and that is why you see the exception. The only way to determine the length of a stream is to read the whole stream and resetting the position to the start when you are done (which you can see is expensive)

     

    Here's one approach: Create a byte array of fixed length and try reading the stream while filling in the byte array in a while loop. After you are done, just reset the position of the stream to the beginning.

     

    Byte[] b = new Byte[1024];

    Stream str = baseMessage.BodyPart.GetOriginalDataStream();

    int temp;

    int counter = 0;

    while ((temp=str.Read(b, 0, b.Length)) > 0)

    {

    counter+=temp;

    }

     

    When this code exists, counter will contain the length of your original stream.

     

    Please note that this code only shows you how to get the length of the stream. The code to reset is not shown.

     

    Thanks

    Mohsin

     

     

    Wednesday, September 19, 2007 8:44 PM
  • I have had this problem occur when using the XML Assemble Pipeline Component to set the Target Charset to ASCII prior to calling a custom pipeline component. Removing the XML Assemble Pipeline Component and doing the conversion inside the custom component resolved this problem.

     

    Hope this infomation helps.

     

    Monday, May 5, 2008 9:16 AM
  • I have experienced this issue with XML disassembler. I have a custom component that appears after the XML disassembler and uses .length to get the length of the message and it throws me this error. However, if i remove the disassembler and run it it runs just fine. I am baffled by this behavior.

    Why does the same function work on the message stream when the xml disassembler component is removed ??? ISnt' the message still a stream in the pipeline ???
     

    Thursday, December 24, 2009 1:51 PM
  • Thanks much, this solution worked for us. Resetting the stream was not needed in our case.
    Wednesday, December 21, 2011 5:18 PM