X
  • WLS
    September 10, 2008

JMS with .NET - WebLogic Server 10gR3 Example

Guest Author

Overview

Update: 9/25/2009 - Since the documentation has moved to OTN, please refer to This link for the 11gR1 release of JMS .NET client documentation.

WebLogic Server 10gR3 contains an officially developed and supported .NET JMS client library for the first time.  Previous versions of WebLogic Server have shipped with C library support which is still included.  Some independent projects were able to use the C libraries to add unofficial .NET support in the past, but this latest WLS release takes things to the next level.  There was a question today in the WLS forums about VB support, so I decided to try the example.  In about 20 minutes I had the C# example working (I had WLS and Visual C# 2008 Express installed previously).  Here are some screenshots and notes from my test.

Software Prerequisites

WebLogic Server 10gR3

Visual C# 2008 Express Edition or your favorite .NET compiler - this one is free and useful for doing the basics

Basic Steps

I started by reviewing the new .NET client documentation for WebLogic Server.  The basic gist of it is the default installation of WLS includes the WebLogic.Messaging.dll library in <WEBLOGIC_INSTALLATION>\modules\com.bea.weblogic.jms.dotnetclient_1.0.0.0.  All you need to do is create a reference to that DLL and your ready to use the .NET WLS JMS API.  In fact, a complete C# example console application is provided in the docs.

Build the C# Client

So the first thing is to do launch Visual C# and create a new project and select the Console Application template.

cs1

cs2

On the right hand side of the window, you should see the Solution Explorer, simply right click on the References and select Add Reference.  You'll need to browse to the WebLogic.Messaging.dll location and click OK.

cs3

csRefBrowse

Then simply replace the existing CS file with the MessagingSample.cs file provided in the documentation.  I found it simple enough to right click on the project and select Add->Class, name the file MessagingSample.cs and paste over the generated contents.  Then I deleted the original .cs file that was created by default for the project.

newclass

Then just save and build the solution.  F6 is the shortcut for this or you can use the menu Build->Build Solution.  My .exe was placed in a location like this, but you can configure it:  D:\MyData\Visual Studio 2008\Projects\WebLogicJMSExample\WebLogicJMSExample\bin\Release

WebLogic Server JMS Configuration

When you look at the source code in the example, you can see that it assumes some basic host and port information along with a basic queue and topic are available in WebLogic Server JMS. 

private string host = "localhost";

private int port = 7001;

private string cfName = "weblogic.jms.ConnectionFactory";

private string queueName = "jms.queue.TestQueue1";

private string topicName = "jms.topic.TestTopic1";


If you use the examples server domain, which you can start from <WEBLOGIC_INSTALLATION>\wlserver_10.3\samples\domains\wl_server\bin\startWebLogic.cmd (sh) then you simply need to add a queue or topic or change the example C# code to point to the JNDI name of your queue and topic.  Here's a screenshot of my examples server JMS module after I've done the configuration.  Notice that I've set both the JNDI name and targeted the queue and topic to the subdeployment.  Click the image to enlarge it. 

csJMSConfig

I had a little trouble with the JNDI tree the first time through because I forgot to target the topic and queue to the subdeployment and therefore the JNDI name wasn't published correctly.  To make sure you got it right, you can check the JNDI tree.  From the console choose Environment->Servers->examplesServer(admin).  The next page should have a link that says "View JNDI Tree".  From there you can validate that the queue and topic are available as you expect.  Since I had made a mistake the first time through, I found that I had to restart WLS to get the JNDI tree correct, but this step should not be necessary if you configure the JMS module correctly the first time.

jndi

Once the JNDI names are verified, try the executable.

D:\MyData\Visual Studio 2008\Projects\WebLogicJMSExample\WebLogicJMSExample\bin\Release>WebLogicJMSExample.exe

WebLogic JMS .NET Client Demo

Settings:

host = localhost

port = 7001

cf = weblogic.jms.ConnectionFactory

queue = jms.queue.TestQueue1

topic = jms.topic.TestTopic1


-- DemoSyncQueueReceiveWithAutoAcknowledge --

t3://localhost:7001

Trying to connect to URL: T3://localhost:7001

Successful in connecting to URL: localhost:7001

Sent Message:

JMSMessageID=ID:<294131.1221078898734.0>

JMSRedelivered=False

JMSXDeliveryCount=

Text=My q message

Received Message:

JMSMessageID=ID:<294131.1221078898734.0>

JMSRedelivered=False

JMSXDeliveryCount=1

Text=My q message


-- DemoAsyncNondurableTopicConsumerAutoAcknowledge --

t3://localhost:7001

Trying to connect to URL: T3://localhost:7001

Successful in connecting to URL: localhost:7001

Sent Message:

JMSMessageID=ID:<294131.1221078899219.0>

JMSRedelivered=False

JMSXDeliveryCount=

Text=My topic message

Received Message Asynchronously:

JMSMessageID=ID:<294131.1221078899219.0>

JMSRedelivered=False

JMSXDeliveryCount=1

Text=My topic message


-- DemoSyncTopicDurableSubscriberClientAcknowledge --

t3://localhost:7001

Trying to connect to URL: T3://localhost:7001

Successful in connecting to URL: localhost:7001

Sent Message To Durable Subscriber:

JMSMessageID=ID:<294131.1221078900406.0>

JMSRedelivered=False

JMSXDeliveryCount=

Text=My durable message

Durable Subscriber Received Message:

JMSMessageID=ID:<294131.1221078900406.0>

JMSRedelivered=False

JMSXDeliveryCount=1

Text=My durable message

Durable Subscriber Received Message Again:

JMSMessageID=ID:<294131.1221078900406.0>

JMSRedelivered=True

JMSXDeliveryCount=2

Text=My durable message


D:\MyData\Visual Studio 2008\Projects\WebLogicJMSExample\WebLogicJMSExample\bin\Release>


After you run the test, you can look at the queue and the topic in the console and go to the monitoring tab.  If the test ran successfully, you should see the message counts and client counts indicate that the test run.

You can download my Visual C# 2008 Solution.

If you plan to use this feature, please contact me at james dot bayer at oracle dot com or leave a comment.  I know the JMS team is very interested to hear how our customers are planning to use the .NET support.

Join the discussion

Comments ( 6 )
  • mauricio Friday, October 10, 2008
    Hi, im trying to write a .net client for a jax-ws service but i did't found some documentation about that, the client works fine without security, maybe you know how to build a secure .net wfc client for weblogic 10gr3 webservice. Thanks a lot.
  • James Bayer Friday, October 10, 2008
    Mauricio, I have not tried the .NET / WLS WS-Security interop before. I'm sure it depends on what type of WS-Security you are using. For example, there are multiple token profiles UserName PW Token, SAML, X.509 Certs, etc. If you figure it out, please write-up your solution somewhere as I'm sure others will find it valuable.
  • Chris Tomkins Wednesday, October 22, 2008
    Great post James - got this up and running really quickly thanks to you.
  • Ashokraj Thursday, November 20, 2008
    Will it be a replacement of J-Integra?
  • James Bayer Thursday, November 20, 2008
    This is not a J-Integra replacement. With WLS 10.3, you can still invoke COM objects by using jCOM and the com2java tool.
    http://edocs.bea.com/wls/docs103/jcom/wlstocom.html#wp1112310

    The .NET JMS client approach is different because it uses native .NET code to send / receive WLS JMS with out requiring a JNI wrapper.

  • Chris Hecker Monday, March 15, 2010
    Note that the bea.com URLs no longer resolve to anything meaningful.
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.