Biztalk------Pipeline中Stream的处理问题

场景:Send Pipeline,在"Assemble" Stage中,用"EDI Assembler"把XML Message解析为EDI文本消息,在"Encode" Stage中,开发一个把消息转化为每行80个字符的文本消息的自定义管道组件。

原始核心代码:   byte[] buffer = new byte[this._prop_BlockWidth];

                     MemoryStream newMS = new MemoryStream();
                     Stream oldStream = inmsg.BodyPart.Data;                 

                     sizeRead = oldStream.Read(buffer, 0, this._prop_BlockWidth);

原始代码的问题:管道处理后的消息,有时不一定是80字符每行。

替代解决代码:
      MemoryStream newMS = new MemoryStream();
      SeekableReadOnlyStream oldStream = new SeekableReadOnlyStream(inmsg.BodyPart.GetOriginalDataStream());
      using (StreamReader sr = new StreamReader(oldStream))
      {
          while (sr.Peek() >= 0)
          {
              c = new char[this._prop_BlockWidth];
              sizeRead = sr.Read(c, 0, c.Length);
          }
          ......     
       }

分析:经过EDI Assembler处理后的Stream是NonSeekable的。

 

你可能感兴趣的:(pipeline)