MSMQ问题 [英] MSMQ Issues
问题描述
大家好我 Hi All 公共 void DownloadMSMQ() { public void DownloadMSMQ()
{ string strSapInPath = "" ; string strSapInPath ="";
string strSapArchaivePath = "" ; string strSapArchaivePath="";
string _strQueuePath = QUEUEPATH; string _strFullQueuePath = _strQueuePath; string _strFullQueuePath = _strQueuePath;
MessageQueue popQ = < span style ="font-size:x-small; color:#0000ff"> new popQ.MessageReadPropertyFilter.SetAll(); MessageQueue popQ = new MessageQueue(_strFullQueuePath);
popQ.MessageReadPropertyFilter.SetAll(); popQ.Formatter = popQ.Formatter = new ActiveXMessageFormatter (); new ActiveXMessageFormatter();
MessageEnumerator Enumerator = popQ.GetMessageEnumerator2(); MessageEnumerator Enumerator = popQ.GetMessageEnumerator2();
int count = 0; int count = 0;
string strSAPINFileName = "" ; string strSAPINFileName = "";
while (Enumerator.MoveNext( new TimeSpan (0,0,2))) { while (Enumerator.MoveNext(new TimeSpan(0,0,2)))
{ count = ++ count; count = ++count; System.Messaging。 System.Messaging. 消息 Msg = Enumerator.Current; Message Msg = Enumerator.Current;
尝试 { Msg.Formatter = Msg.Formatter = new Activ eXMessageFormatter (); new ActiveXMessageFormatter();
object myObject; myObject =( object myObject;
myObject = ( object )Msg.Body; object)Msg.Body;
GC 。收集(); GC.Collect();
//对于SapIn --- // strSAPINFileName = SAPINPATH + Msg.Label; strSAPINFileName = SAPINPATH + Msg.Label; TextWriter Sapin_tw = new StreamWriter (strSAPINFileName); Sapin_tw.Write(( TextWriter Sapin_tw = new StreamWriter(strSAPINFileName);
Sapin_tw.Write(( string )myObject); Sapin_tw.Close(); string)myObject);
Sapin_tw.Close(); Sapin_tw = Sapin_tw = null ; null;
// Sap Archaive ---- // strSapArchaivePath = SAPINARCHIVEPATH + Msg.Label; strSapArchaivePath = SAPINARCHIVEPATH + Msg.Label; TextWriter SapArchaive_tw = new StreamWriter (strSapArchaivePath); SapArchaive_tw.Write(( TextWriter SapArchaive_tw = new StreamWriter(strSapArchaivePath);
SapArchaive_tw.Write(( 字符串 )myObject); SapArchaive_tw.Close(); string)myObject);
SapArchaive_tw.Close(); SapArchaive_tw = SapArchaive_tw = null ; null;
} catch (System.IO。 IOException exIO) { catch (System.IO.IOException exIO)
{ 控制台 。WriteLine(exIO) 。信息); } Console.WriteLine(exIO.Message);
} 最后 { } } // popQ.Purge(); } } 这篇关于MSMQ问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
想要使用Biztalk或.net从MSMQ下载.rar(zip文件)文件
使用biztalk:
我我给我的文件名属性是%SourceFileName%,但这里这个属性不起作用。
然后我来了orchastration但是在这里我不能为此创建消息因为这是rar文件(我们有xml相关消息)。
使用.net代码将rar文件下载到本地文件夹,我遇到问题,我可以在从msmq下载后取消压缩此文件。
错误:未预期结束且没有要提取的文件
我的代码是:
i want download .rar(zip files) files from MSMQ using Biztalk or .net
Using biztalk :
i am giving my filename property is %SourceFileName%,but here this property is not working.
then i came with orchastration but here i can not create message for this bec this is rar file(we have xml related messages ).
using .net code for download rar file into local folder,i am facing problem ,i can un zip this file after downloading from msmq.
Error:un expected end and no files to extract
my code is :
可以帮助我,我错了。
vittalaranga
can help me where i am wrong.
vittalaranga推荐答案
Hi
首先,当从MSMQ接收时,你没有设置文件名 - 你只需指定msmq从适配器中读取。如果您希望在将rar文件提交到消息框之前对其进行解压缩,则需要编写可在解码阶段使用的管道组件来为您执行此操作。如果您只想在业务流程中使用rar文件,那么让业务流程接收一个类型为System.Xml.XmlDocument的消息 - 这将捕获所有内容。
其次,对于您的代码;您可能不希望使用TextWriter来编写二进制文件。
UNTESTED,但尝试这样的事情:
$
Hi
First of all, when receiving from MSMQ, you don't set the filename - you just specify what msmq to read from in the adapter. If you want the rar files to be decompressed before they are submitted to the messagebox, you need to write a pipeline component that you can use in the decode stage to do that for you. If you just want the rar file inside your orchestration, then let the orchestration receive a message that is of type System.Xml.XmlDocument - that will catch all.
Secondly, for your code; You probably don't want to use a TextWriter to write a binary file.
UNTESTED, but try something like this:
System.Messaging.MessageQueue q = new System.Messaging.MessageQueue(@"MyQueue");
q.Formatter = new System.Messaging.ActiveXMessageFormatter();
System.Messaging.Message m = q.Receive();
byte[] bytes = new byte[m.BodyStream.Length];
FileStream fs = File.Create(@"PathToFile");
fs.Write(bytes, 0, bytes.Length);
fs.Close();