ACCESS缓解msmq接收远程主机私有队列音讯的难点!

下边是2个简易的例证据与供词参考;
 

经过调用windows\system32\mqoa.dll 那么些Message Queuing ActiveX
Interface API函数就能够实现;

ACCESS 1ACCESS 2
  1ACCESS 3using System;
  2ACCESS 4using System.Drawing;
  3ACCESS 5using System.Collections;
  4ACCESS 6using System.ComponentModel;
  5ACCESS 7using System.Windows.Forms;
  6ACCESS 8using MSMQ;
  7ACCESS 9namespace MyTest
  8ACCESS 10ACCESS 11ACCESS 12{
  9ACCESS 13ACCESS 14    /**//// <summary>
 10ACCESS 15    /// Form贰 的摘要表明。
 11ACCESS 16    /// </summary>
 12ACCESS 17    public class Form2 : System.Windows.Forms.Form
 13ACCESS 18ACCESS 19    ACCESS 20{
 14ACCESS 21ACCESS 22        Forms#region Forms
 15ACCESS 23        private System.Windows.Forms.GroupBox groupBox1;
 16ACCESS 24        private System.Windows.Forms.Label label1;
 17ACCESS 25        private System.Windows.Forms.Label label2;
 18ACCESS 26        private System.Windows.Forms.Label label3;
 19ACCESS 27        private System.Windows.Forms.GroupBox groupBox2;
 20ACCESS 28        private System.Windows.Forms.TextBox txthost;
 21ACCESS 29        private System.Windows.Forms.TextBox txtpath;
 22ACCESS 30        private System.Windows.Forms.RadioButton trans1;
 23ACCESS 31        private System.Windows.Forms.RadioButton trans2;
 24ACCESS 32        private System.Windows.Forms.GroupBox groupBox3;
 25ACCESS 33        private System.Windows.Forms.Label label4;
 26ACCESS 34        private System.Windows.Forms.Button button1;
 27ACCESS 35        private System.Windows.Forms.Label label5;
 28ACCESS 36        private System.Windows.Forms.Button button2;
 29ACCESS 37        private System.Windows.Forms.TextBox txtmsg;
 30ACCESS 38        private System.Windows.Forms.TextBox txtrece;
 31ACCESS 39ACCESS 40        /**//// <summary>
 32ACCESS 41        /// 必需的设计器变量。
 33ACCESS 42        /// </summary>
 34ACCESS 43        private System.ComponentModel.Container components = null;
 35ACCESS 44
 36ACCESS 45        public Form2()
 37ACCESS 46ACCESS 47        ACCESS 48{
 38ACCESS 49            //
 39ACCESS 50            // Windows 窗体设计器援助所必需的
 40ACCESS 51            //
 41ACCESS 52            InitializeComponent();
 42ACCESS 53
 43ACCESS 54            //
 44ACCESS 55            // TODO: 在 InitializeComponent 调用后加多别的构造函数代码
 45ACCESS 56            //
 46ACCESS 57        }
 47ACCESS 58
 48ACCESS 59ACCESS 60        /**//// <summary>
 49ACCESS 61        /// 清理全数正在利用的财富。
 50ACCESS 62        /// </summary>
 51ACCESS 63        protected override void Dispose( bool disposing )
 52ACCESS 64ACCESS 65        ACCESS 66{
 53ACCESS 67            if( disposing )
 54ACCESS 68ACCESS 69            ACCESS 70{
 55ACCESS 71                if(components != null)
 56ACCESS 72ACCESS 73                ACCESS 74{
 57ACCESS 75                    components.Dispose();
 58ACCESS 76                }
 59ACCESS 77            }
 60ACCESS 78            base.Dispose( disposing );
 61ACCESS 79        }
 62ACCESS 80        #endregion 
 63ACCESS 81
 64ACCESS 82ACCESS 83        Windows 窗体设计器生成的代码#region Windows 窗体设计器生成的代码
 65ACCESS 84ACCESS 85        /**//// <summary>
 66ACCESS 86        /// 设计器支持所需的法子 – 不要使用代码编辑器修改
 67ACCESS 87        /// 此措施的内容。
 68ACCESS 88        /// </summary>
 69ACCESS 89        private void InitializeComponent()
 70ACCESS 90ACCESS 91        ACCESS 92{
 71ACCESS 93            this.groupBox1 = new System.Windows.Forms.GroupBox();
 72ACCESS 94            this.groupBox2 = new System.Windows.Forms.GroupBox();
 73ACCESS 95            this.trans2 = new System.Windows.Forms.RadioButton();
 74ACCESS 96            this.trans1 = new System.Windows.Forms.RadioButton();
 75ACCESS 97            this.label3 = new System.Windows.Forms.Label();
 76ACCESS 98            this.txtpath = new System.Windows.Forms.TextBox();
 77ACCESS 99            this.label2 = new System.Windows.Forms.Label();
 78ACCESS 100            this.txthost = new System.Windows.Forms.TextBox();
 79ACCESS 101            this.label1 = new System.Windows.Forms.Label();
 80ACCESS 102            this.groupBox3 = new System.Windows.Forms.GroupBox();
 81ACCESS 103            this.button2 = new System.Windows.Forms.Button();
 82ACCESS 104            this.txtrece = new System.Windows.Forms.TextBox();
 83ACCESS 105            this.label5 = new System.Windows.Forms.Label();
 84ACCESS 106            this.button1 = new System.Windows.Forms.Button();
 85ACCESS 107            this.txtmsg = new System.Windows.Forms.TextBox();
 86ACCESS 108            this.label4 = new System.Windows.Forms.Label();
 87ACCESS 109            this.groupBox1.SuspendLayout();
 88ACCESS 110            this.groupBox2.SuspendLayout();
 89ACCESS 111            this.groupBox3.SuspendLayout();
 90ACCESS 112            this.SuspendLayout();
 91ACCESS 113            // 
 92ACCESS 114            // groupBox1
 93ACCESS 115            // 
 94ACCESS 116            this.groupBox1.Controls.Add(this.groupBox2);
 95ACCESS 117            this.groupBox1.Controls.Add(this.label3);
 96ACCESS 118            this.groupBox1.Controls.Add(this.txtpath);
 97ACCESS 119            this.groupBox1.Controls.Add(this.label2);
 98ACCESS 120            this.groupBox1.Controls.Add(this.txthost);
 99ACCESS 121            this.groupBox1.Controls.Add(this.label1);
100ACCESS 122            this.groupBox1.Location = new System.Drawing.Point(8, 8);
101ACCESS 123            this.groupBox1.Name = “groupBox1”;
102ACCESS 124            this.groupBox1.Size = new System.Drawing.Size(352, 120);
103ACCESS 125            this.groupBox1.TabIndex = 0;
104ACCESS 126            this.groupBox1.TabStop = false;
105ACCESS 127            this.groupBox1.Text = “MSMQ Configuration”;
106ACCESS 128            // 
107ACCESS 129            // groupBox2
108ACCESS 130            // 
109ACCESS 131            this.groupBox2.Controls.Add(this.trans2);
110ACCESS 132            this.groupBox2.Controls.Add(this.trans1);
111ACCESS 133            this.groupBox2.Location = new System.Drawing.Point(104, 72);
112ACCESS 134            this.groupBox2.Name = “groupBox2”;
113ACCESS 135            this.groupBox2.Size = new System.Drawing.Size(144, 40);
114ACCESS 136            this.groupBox2.TabIndex = 5;
115ACCESS 137            this.groupBox2.TabStop = false;
116ACCESS 138            // 
117ACCESS 139            // trans2
118ACCESS 140            // 
119ACCESS 141            this.trans2.Checked = true;
120ACCESS 142            this.trans2.Location = new System.Drawing.Point(72, 16);
121ACCESS 143            this.trans2.Name = “trans2”;
122ACCESS 144            this.trans2.Size = new System.Drawing.Size(64, 19);
123ACCESS 145            this.trans2.TabIndex = 1;
124ACCESS 146            this.trans2.TabStop = true;
125ACCESS 147            this.trans2.Text = “true”;
126ACCESS 148            // 
127ACCESS 149            // trans1
128ACCESS 150            // 
129ACCESS 151            this.trans1.Location = new System.Drawing.Point(8, 16);
130ACCESS 152            this.trans1.Name = “trans1”;
131ACCESS 153            this.trans1.Size = new System.Drawing.Size(48, 19);
132ACCESS 154            this.trans1.TabIndex = 0;
133ACCESS 155            this.trans1.Text = “true”;
134ACCESS 156            // 
135ACCESS 157            // label3
136ACCESS 158            // 
137ACCESS 159            this.label3.Location = new System.Drawing.Point(8, 88);
138ACCESS 160            this.label3.Name = “label3”;
139ACCESS 161            this.label3.Size = new System.Drawing.Size(88, 23);
140ACCESS 162            this.label3.TabIndex = 4;
141ACCESS 163            this.label3.Text = “Transactional”;
142ACCESS 164            // 
143ACCESS 165            // txtpath
144ACCESS 166            // 
145ACCESS 167            this.txtpath.Location = new System.Drawing.Point(72, 48);
146ACCESS 168            this.txtpath.Name = “txtpath”;
147ACCESS 169            this.txtpath.Size = new System.Drawing.Size(176, 21);
148ACCESS 170            this.txtpath.TabIndex = 3;
149ACCESS 171            this.txtpath.Text = “Private$\\test”;
150ACCESS 172            // 
151ACCESS 173            // label2
152ACCESS 174            // 
153ACCESS 175            this.label2.Location = new System.Drawing.Point(8, 48);
154ACCESS 176            this.label2.Name = “label2”;
155ACCESS 177            this.label2.Size = new System.Drawing.Size(48, 23);
156ACCESS 178            this.label2.TabIndex = 2;
157ACCESS 179            this.label2.Text = “Path”;
158ACCESS 180            // 
159ACCESS 181            // txthost
160ACCESS 182            // 
161ACCESS 183            this.txthost.Location = new System.Drawing.Point(72, 24);
162ACCESS 184            this.txthost.Name = “txthost”;
163ACCESS 185            this.txthost.Size = new System.Drawing.Size(176, 21);
164ACCESS 186            this.txthost.TabIndex = 1;
165ACCESS 187            this.txthost.Text = “127.0.0.1”;
166ACCESS 188            // 
167ACCESS 189            // label1
168ACCESS 190            // 
169ACCESS 191            this.label1.Location = new System.Drawing.Point(8, 24);
170ACCESS 192            this.label1.Name = “label1”;
171ACCESS 193            this.label1.Size = new System.Drawing.Size(48, 23);
172ACCESS 194            this.label1.TabIndex = 0;
173ACCESS 195            this.label1.Text = “Host”;
174ACCESS 196            // 
175ACCESS 197            // groupBox3
176ACCESS 198            // 
177ACCESS 199            this.groupBox3.Controls.Add(this.button2);
178ACCESS 200            this.groupBox3.Controls.Add(this.txtrece);
179ACCESS 201            this.groupBox3.Controls.Add(this.label5);
180ACCESS 202            this.groupBox3.Controls.Add(this.button1);
181ACCESS 203            this.groupBox3.Controls.Add(this.txtmsg);
182ACCESS 204            this.groupBox3.Controls.Add(this.label4);
183ACCESS 205            this.groupBox3.Location = new System.Drawing.Point(8, 136);
184ACCESS 206            this.groupBox3.Name = “groupBox3”;
185ACCESS 207            this.groupBox3.Size = new System.Drawing.Size(352, 176);
186ACCESS 208            this.groupBox3.TabIndex = 1;
187ACCESS 209            this.groupBox3.TabStop = false;
188ACCESS 210            this.groupBox3.Text = “MSMQ Test”;
189ACCESS 211            // 
190ACCESS 212            // button2
191ACCESS 213            // 
192ACCESS 214            this.button2.Location = new System.Drawing.Point(280, 56);
193ACCESS 215            this.button2.Name = “button2”;
194ACCESS 216            this.button2.Size = new System.Drawing.Size(56, 23);
195ACCESS 217            this.button2.TabIndex = 6;
196ACCESS 218            this.button2.Text = “&Receive”;
197ACCESS 219            this.button2.Click += new System.EventHandler(this.button2_Click);
198ACCESS 220            // 
199ACCESS 221            // txtrece
200ACCESS 222            // 
201ACCESS 223            this.txtrece.Location = new System.Drawing.Point(8, 78);
202ACCESS 224            this.txtrece.Multiline = true;
203ACCESS 225            this.txtrece.Name = “txtrece”;
204ACCESS 226            this.txtrece.Size = new System.Drawing.Size(336, 90);
205ACCESS 227            this.txtrece.TabIndex = 5;
206ACCESS 228            this.txtrece.Text = “Hello World “;
207ACCESS 229            // 
208ACCESS 230            // label5
209ACCESS 231            // 
210ACCESS 232            this.label5.Location = new System.Drawing.Point(8, 56);
211ACCESS 233            this.label5.Name = “label5”;
212ACCESS 234            this.label5.Size = new System.Drawing.Size(112, 23);
213ACCESS 235            this.label5.TabIndex = 4;
214ACCESS 236            this.label5.Text = “Receive Message”;
215ACCESS 237            // 
216ACCESS 238            // button1
217ACCESS 239            // 
218ACCESS 240            this.button1.Location = new System.Drawing.Point(280, 24);
219ACCESS 241            this.button1.Name = “button1”;
220ACCESS 242            this.button1.Size = new System.Drawing.Size(56, 23);
221ACCESS 243            this.button1.TabIndex = 3;
222ACCESS 244            this.button1.Text = “&Send”;
223ACCESS 245            this.button1.Click += new System.EventHandler(this.button1_Click);
224ACCESS 246            // 
225ACCESS 247            // txtmsg
226ACCESS 248            // 
227ACCESS 249            this.txtmsg.Location = new System.Drawing.Point(104, 24);
228ACCESS 250            this.txtmsg.Name = “txtmsg”;
229ACCESS 251            this.txtmsg.Size = new System.Drawing.Size(168, 21);
230ACCESS 252            this.txtmsg.TabIndex = 2;
231ACCESS 253            this.txtmsg.Text = “Hello World “;
232ACCESS 254            // 
233ACCESS 255            // label4
234ACCESS 256            // 
235ACCESS 257            this.label4.Location = new System.Drawing.Point(8, 24);
236ACCESS 258            this.label4.Name = “label4”;
237ACCESS 259            this.label4.Size = new System.Drawing.Size(96, 23);
238ACCESS 260            this.label4.TabIndex = 0;
239ACCESS 261            this.label4.Text = “Send Message”;
240ACCESS 262            // 
241ACCESS 263            // Form2
242ACCESS 264            // 
243ACCESS 265            this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
244ACCESS 266            this.ClientSize = new System.Drawing.Size(368, 318);
245ACCESS 267            this.Controls.Add(this.groupBox3);
246ACCESS 268            this.Controls.Add(this.groupBox1);
247ACCESS 269            this.Name = “Form2”;
248ACCESS 270            this.Text = “Form2”;
249ACCESS 271            this.Load += new System.EventHandler(this.Form2_Load);
250ACCESS 272            this.groupBox1.ResumeLayout(false);
251ACCESS 273            this.groupBox2.ResumeLayout(false);
252ACCESS 274            this.groupBox3.ResumeLayout(false);
253ACCESS 275            this.ResumeLayout(false);
254ACCESS 276
255ACCESS 277        }
256ACCESS 278        #endregion
257ACCESS 279
258ACCESS 280        MSMQ.MSMQQueueInfoClass mqinfor=new MSMQQueueInfoClass();
259ACCESS 281        private void Form2_Load(object sender, System.EventArgs e)
260ACCESS 282ACCESS 283        ACCESS 284{
261ACCESS 285            
262ACCESS 286            
263ACCESS 287        }
264ACCESS 288
265ACCESS 289        private void button1_Click(object sender, System.EventArgs e)
266ACCESS 290ACCESS 291        ACCESS 292{
267ACCESS 293            mqinfor.FormatName=”Direct=TCP:” + this.txthost.Text + “\\” + this.txtpath.Text; 
268ACCESS 294            MSMQ.MSMQQueue mq=mqinfor.Open(MSMQ.MQACCESS.MQ_SEND_ACCESS.GetHashCode(),MSMQ.MQSHARE.MQ_DENY_NONE.GetHashCode());
269ACCESS 295            MSMQ.MSMQMessageClass msg=new MSMQMessageClass();
270ACCESS 296            msg.Label=”activeX Test”;
271ACCESS 297            msg.Body=this.txtmsg.Text;
272ACCESS 298            
273ACCESS 299            MSMQ.MSMQTransactionClass MQ_NO_TRANSACTION=new MSMQTransactionClass();
274ACCESS 300            
275ACCESS 301            object a=MQ_NO_TRANSACTION;
276ACCESS 302            msg.Send(mq,ref a);
277ACCESS 303            
278ACCESS 304
279ACCESS 305        }
280ACCESS 306
281ACCESS 307        private void button2_Click(object sender, System.EventArgs e)
282ACCESS 308ACCESS 309        ACCESS 310{
283ACCESS 311            try
284ACCESS 312ACCESS 313            ACCESS 314{
285ACCESS 315                mqinfor.FormatName=”Direct=TCP:” + this.txthost.Text + “\\” + this.txtpath.Text; 
286ACCESS 316            
287ACCESS 317                MSMQ.MSMQQueue mq=mqinfor.Open(MSMQ.MQACCESS.MQ_RECEIVE_ACCESS.GetHashCode(),MSMQ.MQSHARE.MQ_DENY_NONE.GetHashCode());
288ACCESS 318            
289ACCESS 319                MSMQ.MSMQTransactionClass MQ_NO_TRANSACTION=new MSMQTransactionClass();
290ACCESS 320                object a=MQ_NO_TRANSACTION;
291ACCESS 321                bool WantDestinationQueue=false;
292ACCESS 322                object b=WantDestinationQueue;
293ACCESS 323                bool WantBody =true;
294ACCESS 324                object c=WantBody;
295ACCESS 325                long ReceiveTimeout =100;
296ACCESS 326                object d=ReceiveTimeout;
297ACCESS 327                bool WantConnectorType=false;
298ACCESS 328                object e1=WantConnectorType;
299ACCESS 329                MSMQ.MSMQMessage msg=mq.Receive(ref a,ref b,ref c,ref d,ref e1);
300ACCESS 330                this.txtrece.Text=DateTime.Now.ToString() + ” ” + msg.Body.ToString();
301ACCESS 331            }
302ACCESS 332            catch(Exception e2)
303ACCESS 333ACCESS 334            ACCESS 335{
304ACCESS 336                MessageBox.Show(e2.Message);
305ACCESS 337            }
306ACCESS 338        }
307ACCESS 339    }
308ACCESS 340}
309ACCESS 341

相关文章