現在、xml ファイルを受け入れて Excel に変換する BizTalk カスタム送信パイプラインを開発しています。残念ながら、パイプラインをデプロイした後、System.OutOfMemoryException
. IComponent
インターフェイスの Execute メソッドのコードを含めました。すべての提案を歓迎します。
public Microsoft.BizTalk.Message.Interop.IBaseMessage Execute(IPipelineContext pContext, Microsoft.BizTalk.Message.Interop.IBaseMessage inmsg)
{
MemoryStream outMemStream = new MemoryStream();
try
{
if (inmsg.BodyPart.Data != null)
{
// Read the source message coming from the messaging engine and convert it to memory stream
byte[] buffer = new byte[16 * 1024];
using (MemoryStream ms = new MemoryStream())
{
int read;
while ((read = inmsg.BodyPart.Data.Read(buffer, 0, buffer.Length)) > 0)
{
ms.Write(buffer, 0, read);
}
buffer = ms.ToArray();
}
if (buffer != null)
{
var binaryWriter = new BinaryWriter(outMemStream);
binaryWriter.Write(buffer);
}
OpenXMLOffice oOffice = new OpenXMLOffice();
outMemStream.Position = 0;
oOffice.XMLToExcel(outMemStream, TemporaryFileLocation);
inmsg.BodyPart.Data.Position = 0;
inmsg.BodyPart.Data = outMemStream;
pContext.ResourceTracker.AddResource(outMemStream);
}
return inmsg;
}
catch (Exception ex)
{
throw new ApplicationException(String.Format("Error converting XML to Excel:{0} - Stack Trace: {1}", ex.Message, ex.StackTrace));
}
}
受信した最新のエラーは次のとおりです。
ログ名: アプリケーション ソース: BizTalk Server 日付: 2012 年 2 月 14 日午前 9:29:00 イベント ID: 5754 タスク カテゴリ: BizTalk Server レベル: エラー キーワード: クラシック ユーザー: なし コンピューター: IASDev-PC 説明: URI "C:\SeleneFTPFile\Excel\%MessageID%.xml" で送信ポート "ExcelSendPort" のアダプター "FILE" に送信されたメッセージが中断されました。 エラーの詳細: 送信パイプラインの実行中にエラーが発生しました: "IAS.SeleneFTPFile.ExcelEncodePipeline, IAS.SeleneFTPFile, Version=1.0.0.0, Culture=neutral, PublicKeyToken=2add433e7764165f" ソース: "Excel ファイル エンコーダー" 送信ポート: "ExcelSendPort" URI: "C:\SeleneFTPFile\Excel\%MessageID%.xml" 理由: XML から Excel への変換中にエラーが発生しました: タイプ 'System.OutOfMemoryException' の例外がスローされました。- スタック トレース: System.IO.MemoryStream.set_Capacity(Int32 値) で System.IO.MemoryStream.EnsureCapacity (Int32 値) で System.IO.MemoryStream.Write (Byte[] バッファー、Int32 オフセット、Int32 カウント) で IAS.SeleneFTPFile.Components.ExcelPipeline.EncodeExcel.Execute (IPipelineContext pContext、IBaseMessage inmsg) で MessageId: {ED37CDD1-EF0C-46E7-9519-061AF3D4F8A4} インスタンス ID: {B0E448B3-3DAD-4E52-8F87-07C5D5AA5224}