Access a Java Message Service Topic from .NET Using J-Integra® for .NET

Java/J2EE .NET Interoperability Products Page

This example demonstrates how to access a Java Message Service Topic from .NET client. J-Integra® for .NET is a Java interoperability component that bridges Java/J2EE and Microsoft .NET. It provides bi-directional access of Java objects and .NET components.


Use this example as a guideline to show you how to access a Java Message Service (JMS) topic from .NET using J-Integra for .NET. This example illustrates a very simple multi-client chat program. Each .NET client will connect to a JMS topic and add itself as a listener. An event occurs when a message is typed by one of the .NET clients. Each message is then sent to every listening .NET client. This example will access a JMS topic on BEA's Weblogic 8.1 Application Server.

The Steps to Follow will show you how to deploy J-Integra® for .NET correctly for this example.

Note: $USER_INSTALL_DIR$ is the directory where J-Integra for .NET has been installed. If this location contains whitespace characters (e.g. C:\Program Files\...), you may need to include it within "" when referencing it at the command-line.


  1. A platform with Microsoft Visual Studio .NET 2003 (7.1.3088 or higher) installed, or at least the .NET Framework 1.0.3705 or higher. This will be known throughout the example as the .NET platform.

  2. A platform with Weblogic 8.1 and J-Integra for .NET 1.5.1265 (or higher) installed. This will be known throughout the example as the Java platform.

  3. A version of JDK (1.3.1 or higher) installed on the Java platform, and the bin directory included in the path. This required to run the Java server.

  4. Verify that GenService is installed correctly on the .NET platform.

Steps to Follow

  1. Run Janetor to Configure J-Integra for .NET

  2. Run the J-Integra® for .NET Server

  3. Run GenNet and Compile the Proxies

  4. Compile and Run the .NET Client(s)

Run Janetor to Configure J-Integra® for .NET

Perform this step on the Java platform.

In this step, you will need to configure J-Integra for .NET as a server so it can respond to incoming TCP requests. This is done through the Janetor tool.

  1. Windows

    Launch Janetor from the Start Menu.

    java -jar $USER_INSTALL_DIR$\lib\janetor.jar		
  2. Go to File - Open and open janet.xml located in $USER_INSTALL_DIR$\JMS\java_server.

  3. Install your J-Integra for .NET product license. See Installing the J-Integra® for .NET license for further information.

  4. Select default under Local Objects. Here you see that J-Integra for .NET exposes all Java classes as Client Activated Objects (CAO's) at the given machine address and port using TCP.

    Setup local objects in Janetor configuration tool

  5. Select default under Remote Objects. Here you see that J-Integra for .NET is configured to access a CAO using TCP. Notice that URI is blank - this is because there is no one specific endpoint for J-Integra for .NET to call the .NET client's event handler. This is fine, since the client will pass over the correct URI when it first accesses the J-Integra® for .NET server.

    Setup default remote objects in Janetor configuration tool

  6. Before you exit Janetor, save the configuration by going to File - Save.

Run the J-Integra® for .NET Server

Perform this step on the Java platform.

In this step, you will start Weblogic 8.1 and the J-Integra for .NET server.

  1. Start the Weblogic 8.1 Examples Server by executing the startExamplesServer script located in BEA_HOME\weblogic81\samples\domains\examples.

  2. At the command-line, set up the Weblogic 8.1 environment by executing the setExamplesEnv script located in BEA_HOME\weblogic81\samples\domains\examples.

  3. In the same command-line, add $USER_INSTALL_DIR$\lib\janet.jar to the CLASSPATH (note: add, do not overwrite), change directory to $USER_INSTALL_DIR$\examples\JMS\java_server and enter:

    java com.intrinsyc.janet.Main

Run GenNet and Compile the Proxies

Perform this step on the Java platform.

In this step, you will use the GenNet tool to generate .NET proxies for the Java classes.

Note: GenNet saves configuration details to an XML file. For your convenience, the settings described below have already been saved to the file gennet.xml in the directory $USER_INSTALL_DIR$\examples\JMS\java_server. If you'd prefer not to manually enter the settings as instructed below, simply copy this file over to $USER_INSTALL_DIR$ before starting GenNet.
  1. Windows

    Launch GenNet from the Start Menu.


    Change directory to $USER_INSTALL_DIR$ and then enter:

    java -jar lib\gennet.jar
  2. The first screen of GenNet shows a list of machines that have GenService running (screenshot not shown). Select the appropriate one and click Next.

  3. The next screen prompts for the components (JAR files or directories) to be added to the CLASSPATH. Each of these components are required in order for the Java runtime to resolve references to Java classes when generating .NET proxies. You'll need to add the following component:

    - BEA_HOME\weblogic81\lib\weblogic.jar

    Using GenNet generate .NET assemblies for Java objects

    Move on to the next step by clicking Next.

  4. The next screen prompts for the specific Java classes that will have .NET proxies generated for them. Click on Browse... to add the following classes (use the CTRL key to select multiple classes):

    - com.intrinsyc.janet.JNDIContext
    - javax.jms.TopicConnectionFactory
    - javax.jms.Topic
    - javax.jms.TopicPublisher
    - javax.jms.TopicSession
    - javax.jms.Message
    - javax.jms.TopicSubscriber
    - javax.jms.TopicConnection
    - javax.jms.MessageListener
    - javax.jms.TextMessage

    Select Java classes to be exported to .NET in GenNet

    Click on the Filter button and choose not to generate any proxies for the referenced classes as shown below. This will eliminate the number of .NET proxies created.

    Filter Referenced classes in GenNet

    Move on to the next step by clicking Next.

  5. The next screen prompts you to specify the .NET Assembly name along with the output directory. The screen shot may show a different output directory than the Output Directory value shown here, but it should be pointing to $USER_INSTALL_DIR$\examples\JMS\csharp_client\bin\Debug.

    Setup .NET assembly name and output directory in GenNET

  6. You should see a message that the proxy generation was successful. Click Exit to exit GenNet.

    GenNet proxy generation successful

Compile and Run the .NET Client

Perform this step on the .NET platform.

In this final step, you will configure the .NET client(s) using a configuration file, then compile and run it.

  1. Modify remoting_tcp.config in $USER_INSTALL_DIR$\examples\JMS\csharp_client\bin\Debug to look like:

         <client url="tcp://localhost:9099">
           <activated type="com.intrinsyc.janet.JNDIContext, JanetExample"/>
          <channels>         <channel port="0" ref="tcp">          <serverProviders>            <formatter ref="binary" typeFilterLevel="Full"/>          </serverProviders>          <clientProviders>            <formatter ref="binary"/>          </clientProviders>         </channel>      </channels>    </application>  </system.runtime.remoting> </configuration>

    Notice that tcp://localhost:9099 matches what was entered under Local Objects in Janetor. Change accordingly if necessary.

    Note: If you are using a version of .NET Framework lower than 1.1 (1.0.3705), you will need to remove the <serverProviders> tag (and everything in between it). .NET Framework 1.1 introduced new secure serialization - details can be found here.
  2. Perform the following step twice to launch two different chat clients: change directory to $USER_INSTALL_DIR$\examples\JMS\csharp_client\bin\Debug and launch csharp_client.exe.

  3. At this point, you should see two different chat clients. Enter a different name for each client, then type a message in one of the clients and you will see that all clients receive it:

    Access a Java Message Service Topic from .NET client

    Access a Java Message Service Topic from .NET client

© 2007 Intrinsyc Software International, Inc. All rights reserved. Legal