ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » IBM MQ API Support » Visual studio .net and mqseries com interface Get call fails

Post new topic  Reply to topic
 Visual studio .net and mqseries com interface Get call fails « View previous topic :: View next topic » 
Author Message
flowbe
PostPosted: Sat May 25, 2002 7:35 am    Post subject: Visual studio .net and mqseries com interface Get call fails Reply with quote

Newbie

Joined: 25 May 2002
Posts: 1

Hi,

Has anyone successfully used the mqseries com interfaces in any .net language?
I have been trying to work with it in c# and can get to the interface fine and send messages to the queue however when I try to get a message from the queue the get fails with completion code = 2 reason code = 2043 MQRC_OBJECT_TYPE_ERROR. I have mimicked code from vb6 that works just fine but still cant get a message from the queue. I have looked at this error type in the MQseries programming reference and it is only listed for put calls. The only reason I can come up with for this error is that .net is mangling the message or get message options type when it passes it off the com object.
Ayone have any ideas why this is not working?

Here is the code iv been working with

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace WindowsApplication1
{
/// <summary>
/// Summary description for Form1.
/// </summary>

public class Form1 : System.Windows.Forms.Form
{
private MQAX200.MQQueueManager MyMqManager;
private MQAX200.MQSession MyMqSession;
private MQAX200.MQQueue MyQueue;

REMOVED CODE TO SHORTEN FOR POST
}
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

MyMqSession = new MQAX200.MQSessionClass();
//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
REMOVED THIS CODE TO SHORTEN FOR POST
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
REMOVED THIS CODE TO SHORTEN FOR POST
}
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{

Application.Run(new Form1());
}

private void btnConnect_Click(object sender, System.EventArgs e)
{
int OpenOptions;
MyMqSession.ExceptionThreshold = 3;
MyMqManager = (MQAX200.MQQueueManager) MyMqSession.AccessQueueManager(tbQueueMngr.Text);

if(MyMqManager.IsConnected)
{
OpenOptions = (int) MQAX200.MQ.MQOO_INPUT_SHARED + (int) MQAX200.MQ.MQOO_OUTPUT;
MyQueue = (MQAX200.MQQueue) MyMqManager.AccessQueue(tbQueueName.Text, OpenOptions,"","","");
if(MyQueue.IsOpen)
{
sbConnection.Text = "Connected to " + MyMqManager.name + "." + MyQueue.name ;
btnPut.Enabled = true;
btnGet.Enabled = true;
}
}

}

private void btnPut_Click(object sender, System.EventArgs e)
{
MQAX200.MQMessage Message;
MQAX200.MQPutMessageOptions MessageOptions;

Message = (MQAX200.MQMessage) MyMqSession.AccessMessage();
Message.WriteString(tbMessage.Text);
MessageOptions = (MQAX200.MQPutMessageOptions) MyMqSession.AccessPutMessageOptions();


MyQueue.Put(Message, MessageOptions);

if(MyQueue.CompletionCode == 0)
{
tbMessage.Text = "";
}
else if(MyQueue.CompletionCode == 2)
{
sbConnection.Text = "Put Failed, Reason = " + MyQueue.ReasonName;
}

}

private void btnGet_Click(object sender, System.EventArgs e)
{
MQAX200.MQMessage NewMessage;
MQAX200.MQGetMessageOptions MessageOptions;

NewMessage = (MQAX200.MQMessage) MyMqSession.AccessMessage();
MessageOptions = (MQAX200.MQGetMessageOptions) MyMqSession.AccessGetMessageOptions();

if(MyQueue.IsOpen)
{
THIS NEXT CALL WILL FAIL WITH REASON CODE = 2043 REASON NAME = MQRC_OBJECT_TYPE_ERROR

MyQueue.Get(NewMessage,MessageOptions,30);

if(MyQueue.CompletionCode == 0)
{
tbMessage.Text = NewMessage.ReadString(30);
}
else if(MyQueue.CompletionCode == 2)
{
sbConnection.Text = "Get Failed, ReasonCode = " + MyQueue.ReasonCode + " Reason = " + MyQueue.ReasonName;
}
}

}
}
}

Any help or sample code would be greatly appreciated.

Thanks
Back to top
View user's profile Send private message
RogerLacroix
PostPosted: Mon May 27, 2002 2:16 pm    Post subject: Reply with quote

Jedi Knight

Joined: 15 May 2001
Posts: 3264
Location: London, ON Canada

Hi,

I saw your post and I was thinking maybe we could help each other out.

I wrote a couple of simple (command line) MQ applications using C# (last month) but never got the ActiveX component included / linked correctly (e.g. never got an EXE application). After many tries I gave up.

I am using Microsoft's Framework .NET SDK and install it ok (I've written 5 non-MQ applications using C# without any problems). I have MQSeries v5.2 CSD4 installed. (I don't have the Visual Studio .NET - just the Framework .NET SDK)

How did you resolve finding the MQAX200 class? When I code my Build.bat file with the following:
csc.exe /debug+ /out:.\Test1mq.exe /r:MQAX200.dll Test1mq.cs

I get the error:
error CS0006: Metadata file 'MQAX200.dll' could not be found

But the MQAX200.dll is in my path.

If I code my Build.bat file with the following:
csc.exe /debug+ /out:.\Test1mq.exe /r:"C:\Program Files\MQSeries\bin\mqax200.dll" Test1mq.cs

I get the error:
fatal error CS0009: Metadata file 'D:\Program Files\MQSeries\bin\mqax200.dll' could not be opened --
'There isn't metadata in the memory or stream'


Note: I am not a VB person - I prefer Java but C# is interesting.

I think your problem is that some of the default values are not set correctly but I cannot test this out.

later
Roger...
Enterprise Architect
Capitalware Inc.
http://www.capitalware.net
----------------------------------------
IBM Certified Specialist - MQSeries
IBM Certified Developer - MQSeries
IBM Certified Solutions Expert - MQSeries
----------------------------------------
Back to top
View user's profile Send private message Visit poster's website
dpchiesa
PostPosted: Wed May 29, 2002 6:20 pm    Post subject: MQAX from .NET Reply with quote

Apprentice

Joined: 29 May 2002
Posts: 46

To answer the 2nd question, The way to get the MQAX200.dll is to use tlbimp.exe (ships with .NET SDK) or to use Project....Add Reference....COM... and select the MQAX library.

Re the first post, why MQRC_OBJECT_TYPE_ERROR ?
I replicated the result reported, EXCEPT, in order to avoid Invalid Cast exceptions, I had to replace all of the MQAX200.MQXxxx with MQAX200.IMQXxxx200
eg
MQAX200.MQSession => MQAX200.IMQSession200
MQAX200.MQQueue => MQAX200.IMQQueue200

Not sure why this would be so.
_________________
-dpchiesa
Back to top
View user's profile Send private message
dpchiesa
PostPosted: Wed May 29, 2002 7:41 pm    Post subject: MQAX and Reply with quote

Apprentice

Joined: 29 May 2002
Posts: 46

I also tried this in JScript. See below for the code.
It works if I omit the third (optional) param to the Get call. It fails with the same MQRC_OBJECT_TYPE_ERROR if I include the third parameter.

So it doesn't look like a .NET problem, though .NET-> COM interop complicates the issue because the Interop assembly REQUIRES the optional params on the Get() call.


Code:

//
// run with cscript mqaxtest.js
//
// Wed, 29 May 2002  20:24
//

var MQSession= new ActiveXObject("MQAX200.MQSession");
try {
  var qm = MQSession.AccessQueueManager("");
  if (MQSession.reasonCode != 0) {
    WScript.Echo("AQM rc= " + MQSession.reasonCode);
  }
  else {
    WScript.Echo ("Using QM: '" + qm.Name + "'");

    //  MQOO_OUTPUT   +  MQOO_INPUT_AS_Q_DEF
    var q = qm.AccessQueue("postcard", 16 | 1) ;

    // do the get
    var gmsg = MQSession.AccessMessage();
    var  gmo = MQSession.AccessGetMessageOptions();

    // this works
    //q.Get(gmsg, gmo);

    // this fails with MQRC_OBJECT_TYPE_ERROR
    var mlength= 30;
    q.Get(gmsg, gmo, mlength);

    var gs = gmsg.ReadString(gmsg.MessageLength);

    WScript.Echo ("Got message: '" + gs + "'");
  }
}
catch (e) {
  WScript.Echo("Exception!");
  WScript.Echo("Description:" + e.description);
}


_________________
-dpchiesa
Back to top
View user's profile Send private message
dpchiesa
PostPosted: Wed May 29, 2002 7:57 pm    Post subject: Solution - System.Reflection.Missing.Value Reply with quote

Apprentice

Joined: 29 May 2002
Posts: 46

I was able to get this to work by passing a System.Reflection.Missing.Value as the third (optional) param to the Get() call. Eg, replace the offending line with:

Code:

MyMqQueue.Get(NewMessage,MessageOptions,System.Reflection.Missing.Value);


So it works.
_________________
-dpchiesa
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ API Support » Visual studio .net and mqseries com interface Get call fails
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.