Discussion:
XMS.NET type initializer error
(too old to reply)
c***@mclaneat.com
2007-04-04 13:58:48 UTC
Permalink
Hey guys,

I am writing a C# app with XMS.NET directly translated from that nice IronPython/XMS.NET example on the web.

I verified that I can publish and subscribe using MQ Explorer but for some reason when I try to do this with my C# app I get the following error:

"The type initializer for 'IBM.XMS.WMQ.WmqConnectionFactory' threw an exception."

Here is my code for the subscriber portion of my app and thanks for the help:

namespace IronPythonToCSharp_Subscriber
{
class Program
{
static void Main(string[] args)
{
string host = "localhost";
string port = "1414";
string mode = "1";
string qm = "QM1";
int timeout = 10000;

try
{
//create the connection factory
XMSFactoryFactory ff = XMSFactoryFactory.GetInstance(XMSC.CT_WMQ);

//use the connection factory factory to create a connection factory
IConnectionFactory cf = ff.CreateConnectionFactory();

//set the properties
cf.SetStringProperty(XMSC.WMQ_HOST_NAME, host);
cf.SetStringProperty(XMSC.WMQ_PORT, port);
cf.SetStringProperty(XMSC.WMQ_CONNECTION_MODE, mode);
cf.SetStringProperty(XMSC.WMQ_QUEUE_MANAGER, qm);

//create a connection
IConnection connection = cf.CreateConnection();
Console.WriteLine("Connection created");

//create a session
ISession session = connection.CreateSession(false, AcknowledgeMode.AutoAcknowledge);
Console.WriteLine("Session created");

//create a destination
IDestination destination = session.CreateTopic("topic://xms/test");
Console.WriteLine("Destination created");

//create a subscriber
IMessageConsumer subscriber = session.CreateConsumer(destination);
Console.WriteLine("Subscriber created!");

//start the connection
connection.Start();

//receive the message
Console.WriteLine("Waiting for message...");
IMessage recvMsg = subscriber.Receive(timeout);
Console.WriteLine(recvMsg);
Console.WriteLine("Message received!");

//tidy up all the resources
subscriber.Close();
Console.WriteLine("Publisher closed");

session.Close();
Console.WriteLine("Session closed");

connection.Close();
Console.WriteLine("Connection closed");

//we're finished
Console.WriteLine("Sample execution SUCCESSFUL");
}
catch (XMSException e)
{
Console.WriteLine(e.Message);
Console.WriteLine("Sample execution FAILED!");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine("Sample execution FAILED!");
}
}
}
}
SaketR
2007-04-05 04:32:07 UTC
Permalink
Chris,

I tried the source you've posted, and it did not result in an error.

Could you post the details of the error you notice?

What version of XMS .NET are you using? (on command line, set
XMS_TRACE_ON=1, execute your App, open the resulting trace file, and see
the header information).
--
Warm regards,
Saket

wastedmonkeys.com

a Hursley view on WebSphere MQ @ http://hursleyonwmq.wordpress.com
c***@mclaneat.com
2007-04-05 14:59:05 UTC
Permalink
Hello and thanks for replying!

I went ahead and installed the required Refresh and Fix packs. Now I am receiving a different error on a different line of code. Thanks!

It happens on this line:
IDestination destination = session.CreateTopic("topic://xms/test");

Here is the exception information I received:
{IBM.XMS.XMSException: CWSMQ0006E: An exception was received during the call to the method WmqSession.SetupPubSub: CompCode: 2, Reason: 2085. During execution of the specified method an exception was thrown by another component. See the linked exception for more information.
at IBM.XMS.WMQ.WmqSession.ThrowExceptionReceived(Object[] messageParams, Exception caughtException, String probeId)
at IBM.XMS.WMQ.WmqSession.SetUpPubSub(Boolean startCleanup)
at IBM.XMS.WMQ.WmqSession.CreateTopic(String topicName)
at IronPythonToCSharp_Subscriber.Program.Main(String[] args) in C:\XMS_NET\IronPythonToCSharp\IronPythonToCSharp_Subscriber\Program.cs:line 41

Linked Exception : CompCode: 2, Reason: 2085}
c***@mclaneat.com
2007-04-05 15:27:50 UTC
Permalink
Just to be clear, I have set this up a local machine and am trying to publish and subscribe on the same machine.

I have created a Queue manager named QM1 and a queue named Q1.
I have checked the spelling as well.

No channels have been created.
Default listener is there and hasn't been modified.

Error is: Reason 2085.

Am I missing something I should have configured?

Thanks again, Chris
Martin
2007-04-05 18:27:30 UTC
Permalink
Post by c***@mclaneat.com
Error is: Reason 2085.
Am I missing something I should have configured?
Hi Chris

Check out the MQ documentation for 2085 which is a reason code. It means an
attempt was made to open an object (eg. a queue) but that a name was
specified that MQ didn't recognise.

Hence you've probably mis-spelled the queue name somewhere.

Note that case is important - check outputs from runmqsc "display qlocal(*)"
to see a list of local queue names on the queue manager

Regards
Martin
c***@mclaneat.com
2007-04-05 18:48:01 UTC
Permalink
Hi Martin,

That's just the thing. My code doesn't specify a queue name but yet worked for some other guy on a different forum. The Queue manager name is QM1. I have checked the spelling many times.

Is there something I may not have setup right?

What should the correct steps be in MQ Explorer?

1) Create queue manager
2) Create queue
3)?
4)?

I do always start the broker before I attempt to run the code.

Thanks for your help,

Regards,

Chris
SaketR
2007-04-10 13:56:13 UTC
Permalink
It may be a case that JMS Publish/Subscribe queues are missing. Try the
documentation, for example:

http://publib.boulder.ibm.com/infocenter/wmqv6/v6r0/index.jsp?topic=/com.ibm.mq.csqzaw.doc/uj10650_.htm
--
Warm regards,
Saket

wastedmonkeys.com

a Hursley view on WebSphere MQ @ http://hursleyonwmq.wordpress.com
c***@mclaneat.com
2007-04-12 13:23:28 UTC
Permalink
Ok, I will give it a shot.

Thank you!

V/R

Chris
c***@mclaneat.com
2007-04-13 13:04:58 UTC
Permalink
That worked!!! Thank you so much!!! I do have one more question.

In the following code:
---------------------------

//receive the message
Console.WriteLine("Waiting for message...");
IMessage recvMsg = subscriber.Receive(timeout);

Console.WriteLine(recvMsg);
Console.WriteLine("Message received!");

-----------------------------
recvMsg contains the message that was sent plus a bunch of header information.
How do I grab and display just the Text of the message and not the other stuff?

Thanks again!!!
Phil Willoughby
2007-04-13 13:52:02 UTC
Permalink
Post by c***@mclaneat.com
That worked!!! Thank you so much!!! I do have one more question.
---------------------------
//receive the message
Console.WriteLine("Waiting for message...");
IMessage recvMsg = subscriber.Receive(timeout);
/* from memory, which may be unreliable... */
ITextMessage txtRecvMsg = (ITextMessage)recvMsg;
Console.WriteLine(txtRecvMsg.Text);
Post by c***@mclaneat.com
Console.WriteLine(recvMsg);
Console.WriteLine("Message received!");
-----------------------------
recvMsg contains the message that was sent plus a bunch of header information.
How do I grab and display just the Text of the message and not the other stuff?
Thanks again!!!
c***@mclaneat.com
2007-04-17 13:35:14 UTC
Permalink
That worked! Thanks Phil!

Loading...