c***@mclaneat.com
2007-04-04 13:58:48 UTC
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!");
}
}
}
}
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!");
}
}
}
}