In previous posts, we presented a simple WebLogic JMS client in Java here, and an updated one here. We also presented a simple C# JMS program here.
In this post, we present a more or less equivalent C#/.Net implementation of the updated simple JMS client. Please refer to the referenced posts for details of how to set up the necessary queues, etc. on WebLogic, and how to build and use this code.
Update: You can grab this code from our Subversion repository:
svn checkout https://www.samplecode.oracle.com/svn/jmsclients/trunk
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WebLogic.Messaging;
namespace SimpleJMSClient
{
class Program
{
private static string DEFAULT_URL = "t3://localhost:7101";
private static string cfName = "weblogic.jms.ConnectionFactory";
private static string DEFAULT_QUEUE = "jms/MarksQueue";
private static string DEFAULT_USER = "weblogic";
private static string DEFAULT_PASSWORD = "weblogic1";
static void Main(string[] args)
{
sendMessage("hello from .net with 1 arg");
sendMessage("t3://localhost:7101",
"weblogic",
"weblogic1",
"jms/MarksQueue",
"hello from .net with 5 args");
}
static void sendMessage(string messageText)
{
sendMessage(DEFAULT_URL,
DEFAULT_USER,
DEFAULT_PASSWORD,
DEFAULT_QUEUE,
messageText);
}
static void sendMessage(string url, string user, string password, string queueName, string messageText)
{
// create properties dictionary
IDictionary<string, Object> paramMap = new Dictionary<string, Object>();
// add necessary properties
paramMap[Constants.Context.PROVIDER_URL] = url;
paramMap[Constants.Context.SECURITY_PRINCIPAL] = user;
paramMap[Constants.Context.SECURITY_CREDENTIALS] = password;
// get the initial context
IContext context = ContextFactory.CreateContext(paramMap);
// lookup the connection factory
IConnectionFactory cf = context.LookupConnectionFactory(cfName);
// lookup the queue
IQueue queue = (IQueue)context.LookupDestination(queueName);
// create a connection
IConnection connection = cf.CreateConnection();
// start the connection
connection.Start();
// create a session
ISession session = connection.CreateSession(
Constants.SessionMode.AUTO_ACKNOWLEDGE);
// create a message producer
IMessageProducer producer = session.CreateProducer(queue);
producer.DeliveryMode = Constants.DeliveryMode.PERSISTENT;
// create a text message
ITextMessage textMessage = session.CreateTextMessage(messageText);
// send the message
producer.Send(textMessage);
// CLEAN UP
connection.Close();
context.CloseAll();
}
}
}

Pingback: Simple JMS client in Scala | RedStack
Pingback: An updated simple WebLogic JMS client | RedStack
Pingback: An updated simple WebLogic JMS client