Build a small 'hello world' console application with C# as client and a J2EE
Application server.
The client calls the function 'hello' on the server with a name as parameter
and displays the result.
Write an EJB for your J2EE server, create IDL files, generate .NET C# code and write the .NET client.
Write an EJB with the following interfaces and implementation.
Create the jar/ear files and deploy it to your J2EE Server.
package Hello; import javax.ejb.EJBObject; public interface Greetings_Remote extends EJBObject { public String hello ( String name) throws java.rmi.RemoteException; } |
package Hello; import java.rmi.RemoteException; import javax.ejb.SessionBean; import javax.ejb.SessionContext; import javax.ejb.CreateException; public class Greetings_Bean implements SessionBean { public Greetings_Bean () { super (); } private SessionContext m_ctx = null; public void setSessionContext (SessionContext ctx) {m_ctx = ctx;} public void ejbCreate () throws RemoteException, CreateException {System.out.println ("ejbCreate () on " + this);} public void ejbRemove () {System.out.println ("ejbRemove () on " + this);} public void ejbActivate () {System.out.println ("ejbActivate () on " + this);} public void ejbPassivate () {System.out.println ("ejbPassivate() on " + this);} public String hello ( String name) throws java.rmi.RemoteException { return "Greeting from J2EE Server to " + name; }; } |
package Hello; import java.rmi.RemoteException; import javax.ejb.CreateException; import javax.ejb.EJBHome; public interface Greetings_Home extends EJBHome { public Greetings_Remote create () throws RemoteException, CreateException; } |
Please make sure you modify the path to J2EE.jar.
> set J2EE_PATH=%CLASSPATH%;C:\Sun\AppServer\lib\j2ee.jar > BrewerCmd -cp .\ejb\assemble\jar\helloEjb.jar;%J2EE_PATH% -v -d .\IDL -g idl Hello.Greetings_Home |
> BrewerCmd -g cs -d .\DotnetClient\Generated .IDL\Hello.idl |
Please make sure you modify the path to J2EE.jar.
> set J2EE_PATH=%CLASSPATH%;C:\Sun\AppServer\lib\j2ee.jar > BrewerCmd -cp .\ejb\assemble\jar\helloEjb.jar;%J2EE_PATH% -v -d .\DotnetClient\Generated -g cs Hello.Greetings_Home |
Implementation: main.cs
Generated : Hello.cs
a.) Create a console application
b.) Add a reference to '$ESPRESSO_INSTALL_DIR$/bin/Jintegra.Espresso.dll'
c.) Add the generated file: ./IDL/Hello.cs
d.) Write the client:
using System; using Ics.J2EE; using Ics.Runtime; namespace DotNetClient { class HelloClient { static void Main(string[] args) { Console.WriteLine( "Hello-Client\n" +"\t(c) 2007 Intrinsyc Software International, Inc. All rights reserved.\n" +"\tCORBA Demo"); HelloClient oHelloClient = new HelloClient(); oHelloClient.run( args); Console.WriteLine( "bye"); } private void run(string[] args) { Hello.Greetings_Remote oGreetings; J2eeQuickConfig qc = new J2eeQuickConfig(ApplicationServer.SUN_JDK_RMI_IIOP); // For Sun application Server qc.SetNamingServicePort(3700); // Set the host //qc.SetApplicationServerHost("some_machine"); // Default Java version 1.4.2. Options are JDK_131, JDK_141, JDK_142 and JDK_150 qc.SetTargetJavaVersion(JavaVersion.JDK_150); // Turn on log with name Log.txt and without appending exist log file // qc.SetApplicationLog(OrbErrorLevel.ERRORS, "Log.txt", false); J2eeEasyContext.Init(qc); Hello.Greetings_Home oGreetingsHome = (Hello.Greetings_Home) J2eeEasyContext.Lookup("ejb/Hello", "Hello.Greetings_Home"); oGreetings = oGreetingsHome.create(); string strRet = oGreetings.hello("Ics Client"); System.Console.WriteLine("{0}", strRet); System.Console.WriteLine("Press Enter to exit."); System.Console.ReadLine(); J2eeEasyContext.ShutdownRuntime(); } } } |
> asadmin start-domain domain1 |
> copy ..\assemble\ear\Hello.ear c:\Sun\AppServer\domains\domain1\autodeploy |