Access Enterprise Java Beans in WebLogic 6.1 from .NET Using J-Integra® for .NET |
![]() |
This example demonstrates how to access Enterprise Java Beans in WebLogic 6.1 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 your Enterprise Java Beans (EJB) from a .NET client, using J-Integra for .NET. This example will be deployed on BEA's Weblogic 6.1 Application Server.
The Steps to Follow will show you how to deploy J-Integra® for .NET as a Java Servlet in Weblogic 6.1 to interpret the HTTP requests from a .NET client. Refer to the diagram below for an overview of the scenario:
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.
A platform with Weblogic 6.1 and J-Integra for .NET 1.5.1265 (or higher) installed. This will be known throughout the example as the Java platform.
Verify that GenService is installed correctly on the .NET platform.
Perform this step on the Java platform.
In this step, you will need to configure J-Integra for .NET to act as a Servlet. This is done through the Janetor tool.
Launch Janetor from the Windows Start Menu.
java -jar $USER_INSTALL_DIR$\lib\janetor.jar
Select File - Open and open janet.xml located in $USER_INSTALL_DIR$\examples\bea_weblogic_61_http\java_server.
Install your J-Integra for .NET product license. See Installing the J-Integra® for .NET license for further information.
Select default under Local Objects. Here you see that the J-Integra for .NET Servlet can be accessed with a URI that will be constructed from the configuration details shown. Any Java classes will also be accessed as the specified Assembly name from the .NET client. If required, change the details to point to the WebLogic 6.1 host name/port number.
In the EJB Context tab you see the properties required to access EJB's (not shown). If required, change Provider URL to your Weblogic 6.1 provider URL.
Do not exit Janetor yet as you'll need it for the next step.
Perform this step on the Java platform.
In this step, you will use the Janetor tool to generate a WAR file. This WAR file will include the J-Integra for .NET runtime acting as a Java Servlet along with the EJB proxies required to access the EJB.
Back in Janetor, go to File -Export web application archive.
The screenshot below shows the Export web application archive window. See the documentation for Janetor for a description of all the fields. Change Output file as necessary.
To generate a WAR file click OK.
Before you exit Janetor, save the configuration by going to File - Save.
Perform this step on the Java platform.
In this step, you will deploy both the EJB and the WAR file from Janetor on Weblogic 6.1. The EJB represents a simple bank that allows you to create/deposit/withdraw from accounts. It is the "beanManaged" example that comes with Weblogic 6.1, and can be found in BEA_HOME\wlserver6.1\samples\examples\ejb\basic\beanManaged
Follow the Weblogic 6.1 documentation to build the EJB and copy the resulting JAR file to the WebLogic 6.1 "auto-deploy" directory. For deploying it under the Examples Server, the deploy directory would be BEA_HOME\wlserver6.1\config\examples\applications.
Copy the WAR file, AccountEjb.war located in $USER_INSTALL_DIR$\examples\bea_weblogic_61_http\java_server to the WebLogic 6.1 "auto-deploy" directory. For deploying it under the Examples Server, the deploy directory would be BEA_HOME\wlserver6.1\config\examples\applications.
Start the Examples Server by executing the startExamplesServer script located in BEA_HOME\wlserver6.1\config\examples. Watch the output for any exceptions encountered. If there are none, you have successfully deployed the EJB and WAR file.
Perform this step on the Java platform.
In this step, you will use the GenNet tool to generate .NET proxies for the EJB, along with the JNDI Context required to instanciate the Home object.
Launch GenNet from the Start Menu.
Change directory to $USER_INSTALL_DIR$ and then enter:
java -jar lib\gennet.jar
The first screen of GenNet shows a list of machines that have GenService running (screenshot not shown). Select the appropriate one and click Next.
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 components:
- $USER_INSTALL_DIR$\examples\bea_weblogic_61_http\java_server\beanmanagedclient.jar
- BEA_HOME\wlserver6.1\lib\weblogic.jar
Change the location of the WebLogic 6.1 installation location as necessary.
Move on to the next step by clicking Next.
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
- examples.ejb.basic.beanManaged.AccountHome
- examples.ejb.basic.beanManaged.Account
You can also filter out classes that you won't need, so that GenNet will not generate .NET proxies for them. Click on the Filter button and choose to only generate proxies for java.util.Enumeration as shown below:
Move on to the next step by clicking Next.
The next screen prompts you to specify the .NET Assembly name along with the output directory. The screenshot may show a different output directory than what Output Directory is, but it should be pointing to $USER_INSTALL_DIR$\examples\bea_weblogic_61_http\csharp_client\bin\Debug.
You should see a message that the proxy generation was successful. Click Exit to exit GenNet.
Perform this step on the .NET platform.
In this final step, you will configure the .NET client using a configuration file, then compile and run it.
Along with .NET proxies, GenNet generates .NET configuration files to be used as templates - one for the HTTP channel and one for the TCP channel. As the .NET client will be using HTTP to connect to the EJB, we will modify remoting_http.config. You can find this in the same directory that the proxies were generated in.
Modify remoting_http.config to look like:
<configuration> <system.runtime.remoting> <application> <client url="http://localhost:7001/AccountEjb"> <activated type="com.intrinsyc.janet.JNDIContext, JavaClasses"/> </client> <channels> <channel ref="http"> <clientProviders> <formatter ref="binary"/> </clientProviders> </channel> </channels> </application> </system.runtime.remoting> </configuration> |
Notice that http://localhost:7001/AccountEjb matches what was entered under Local Objects in Janetor. Change accordingly if necessary.
Load csharp_client.sln located in $USER_INSTALL_DIR$\examples\bea_weblogic_61_http\csharp_client with Visual Studio .NET 2003. Press F5 to run, or simply run the executable in the bin\Debug directory.
You should see the following output:
Trying to find account with id: ID: 0 Trying to find account with id: ID: 1 Trying to find account with id: ID: 2 Trying to find account with id: ID: 3 Trying to find account with id: ID: 4 Trying to find account with id: ID: 5 Trying to find account with id: ID: 6 Trying to find account with id: ID: 7 Trying to find account with id: ID: 8 Trying to find account with id: ID: 9 Trying to find account with id: ID: 10 Trying to find account with id: ID: 11 Trying to find account with id: ID: 12 Trying to find account with id: ID: 13 Trying to find account with id: ID: 14 Trying to find account with id: ID: 15 Trying to find account with id: ID: 16 Trying to find account with id: ID: 17 Trying to find account with id: ID: 18 Trying to find account with id: ID: 19 Account: :ID: 0 has a balance of 0 Account: :ID: 1 has a balance of 1000 Account: :ID: 2 has a balance of 2000 Account: :ID: 3 has a balance of 3000 Account: :ID: 4 has a balance of 4000 Account: :ID: 5 has a balance of 5000 Account: :ID: 6 has a balance of 6000 Account: :ID: 7 has a balance of 7000 Account: :ID: 8 has a balance of 8000 Account: :ID: 9 has a balance of 9000 Account: :ID: 10 has a balance of 10000 Account: :ID: 11 has a balance of 11000 Account: :ID: 12 has a balance of 12000 Account: :ID: 13 has a balance of 13000 Account: :ID: 14 has a balance of 14000 Account: :ID: 15 has a balance of 15000 Account: :ID: 16 has a balance of 16000 Account: :ID: 17 has a balance of 17000 Account: :ID: 18 has a balance of 18000 Account: :ID: 19 has a balance of 19000 Querying for accounts with a balance greater than 5000... Account ID: 6; balance is $6000 Account ID: 7; balance is $7000 Account ID: 8; balance is $8000 Account ID: 9; balance is $9000 Account ID: 10; balance is $10000 Account ID: 11; balance is $11000 Account ID: 12; balance is $12000 Account ID: 13; balance is $13000 Account ID: 14; balance is $14000 Account ID: 15; balance is $15000 Account ID: 16; balance is $16000 Account ID: 17; balance is $17000 Account ID: 18; balance is $18000 Account ID: 19; balance is $19000 Removing beans...