Click here to Skip to main content
11,576,963 members (53,849 online)
Click here to Skip to main content

Building a Distributed Object System with .NET and J2EE Using IIOP.NET

, 1 Jul 2003 240.1K 3.4K 93
Rate this:
Please Sign up or sign in to vote.
This article demonstrates the use of IIOP.NET

Introduction

In Microsoft's vision, the next generation of distributed systems will communicate with WebServices. WebServices are great when it comes to integrate heterogeneous loosely coupled systems, but they have their limitations too: they have no support for remote object references. In practice, they are stateless and closer to a remote method call than to a distributed object system. Furthermore, SOAP and XML are by no means a compressed format and tend to be quite verbose.

.NET and J2EE are two similar but disjointed worlds: they currently can interact together only using WebServices. Both platforms offer great mechanisms for building tightly coupled distributed object systems: .NET's Remoting and Java's RMI, but sadly these rely on incompatible standards. Luckily, .NET's remoting is highly configurable: a different formatter for the serialization and deserialization of the objects together with a different transport channel can be easily provided.

Fig.1: Overview of a .NET channel

This article shows how the .NET and J2EE platforms can tightly interoperate together, as it is often needed when developing distributed enterprise applications. For this purpose, we use an open-source custom remoting channel called IIOP.NET.

About IIOP.NET

IIOP.NET is a .NET remoting channel based on the IIOP protocol. IIOP is the protocol defined by the CORBA standard, the same used by Java's RMI/IIOP. IIOP.NET acts as an ORB (a CORBA object request broker); it converts .NET's type system to CORBA's type system and back, making the objects defined in your application accessible to other ORBs. RMI/IIOP implements a subset of the ORB functionalities (due to some limitations in Java's type system) and provides the same features as IIOP.NET for the J2EE platform.

Fig.2: Overview of a the distributed object system

Using IIOP.NET is almost as simple as using the built-in remoting. The following example will show you how to access a .NET service from Java using IIOP.NET.

IIOP.NET is an open-source project hosted on sourceforge (http://iiop-net.sourceforge.net/). It was developed by Dominic Ullmann as part of his diploma thesis at ETH-Z; further work is now sponsored by his current employer (http://www.elca.ch).

Not surprisingly, IIOP.NET is not the only software you can use for this purpose. First, the open-source project Remoting.Corba is quite similar in its goals, but has no generator for creating the IDL from a dll and currently does not support CORBA's valuetypes; second, Janeva from Borland promises to do the same, but is neither free nor available yet (should be released in summer '03). We choose IIOP.NET because it is free, currently available, and has a tool to generate the IDL automatically.

The example: accessing a generic collection service

Your problem: you just implemented a great service using .NET, but your customer insists on using a Java client; You cannot use WebServices, because the client software needs to keep references to the single objects on the server: this is just not possible using WebServices unless you implement your own naming service, lease manager, and distributed garbage collection. A more appropriate approach is to use RMI/IIOP on the Java side and IIOP.NET on the .NET side.

This article is constructed around a non-trivial example (the GenericCollection tutorial in the IIOP.NET release: a .NET server provides access to a set of collections consisting of key / value pairs. A client can grab a collection, modify it by adding more pairs, or querying it about the pairs it contains. This requires the client to hold references to the objects on the server.

For the sake of simplicity, we will concentrate on the object distribution, and skip all the concurrency-related problems.

Step 1: install IIOP.NET

You will find a few directories:

  • IIOPChannel contains the channel code
  • CLSToIDLGenerator contains a generator to create the IDL definition files from a .NET assembly
  • Examples contains the examples and tutorials code. The one presented in this article is GenericCollections.

To be able to use IIOP.NET, you need Microsoft's .NET Frameword (1.0 or 1.1) and the C# compiler. The Java part of the demo requires any Java system supporting RMI/IIOP (e.g. Sun's Java SDK 1.4).

To install IIOP.NET, first unpack it; them copy the ir.idl and orb.idl files from your Java SDK lib directory into IIOP.NET's IDL directory. Compile by executing nmake in the main directory.

Step 2: define the service

When you define a .NET service, you have the choice between objects marshalled by reference, which subclass MarshalByRefObject, and objects marshalled by value, which implement ISerializable or are decorated with SerializableAttribute. In the GenericCollections example, the objects (without implementation) are defined as:

namespace Ch.Elca.Iiop.Demo.StorageSystem {
         [Serializable]
         public struct Entry {
                 public string key;
                 public string value;
         }
         public class Container: MarshalByRefObject {
                 public Container() {...}
                 public Entry[] Enumerate() {...}
                 public void    SetValue(string key, string value) {...}
                 public void    SetEntry(Entry e) {...}
                 public String  GetValue(string key) {...}
         }
         public class Manager: MarshalByRefObject {
                 public Manager() {...}
                 public Container   CreateContainer() {...}
                 public Container[] FilterContainers(Entry[] filter) {...}
                 public void        DeleteContainer(Container c) {...}
         }
}

In practice, Manager and Container objects stay on the server. The client merely receives a remote reference to them and works with a proxy object that serializes (i.e. encodes) the method calls and forwards them to the server. On the other hand, Entry structures are entirely copied to the client, which works with its own Entry clones.

You can now make the managed object available to the rest of the (IIOP) world:

public class Server {
    [STAThread]
    public static void Main(string[] args) {
        // register the channel
        int port = 8087;
        IiopChannel chan = new IiopChannel(port);
        ChannelServices.RegisterChannel(chan);
        // publish the adder
        Manager manager = new Manager();
        string objectURI = "manager";
        RemotingServices.Marshal(manager, objectURI);
         
        Console.WriteLine("server running");
        Console.ReadLine();
    }
}

The above code installs an ORB listening on the URI iiop://localhost:8087/, and registers a manager instance under the name "manager" to all channels. The manager object will handle all requests (in fact, this is a server-activated singleton object).

Step 3: create the IDL description

To be able to access these objects from Java, their definition must be made available. Because Java does not understand .NET's metadata, we create a description of the objects using the IDL format using the IIOP.NET's CLSToIDLGenerator tool; this tool takes as input one type and one assembly, and emits the corresponding IDL definition file. It also recursively emits the definitions for all other types used.

Calling

CLSToIDLGenerator Ch.Elca.Iiop.Demo.StorageSystem.Manager Service.dll

generates the description for the Manager type (the full type name is required) defined in the Service.dll assembly and for all other types used by Manager. Manager.idl, Container.idl, and Entry.idl are created.

Step 4: create the Java stubs from the IDL

The Java SDK provides the idlj compiler to generate the java stubs for the IDL files. Note that you will need two more IDL files present in your Java SDK: orb.idl and ir.idl, which contain all the predefined CORBA objects for your Java platform.

Step 5: implement the client

You can now implement a client, which accesses the remote objects defined previously.

import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import Ch.Elca.Iiop.GenericUserException;
import Ch.Elca.Iiop.Demo.StorageSystem.*;

Manager m = null;
try {
         InitialContext ic = new InitialContext();
         Object obj = ic.lookup("manager");
         m = (Manager) PortableRemoteObject.narrow(obj, Manager.class);
         ... use m ...
} catch (Exception e) {
         System.out.println("Exception: " + e.getMessage());
}

This code retrieves a reference to the remote object. Now you can call the methods defined in the remote object just like normal methods:

Container c = m.CreateContainer();
c.SetValue("name","Patrik");

There is still one catch: you must write and implement the class EntryImpl . The Manager and Container types are accessed by reference, i.e. idlj generates a proxy that forwards all method calls to the server. The Entry structure instead is copied to the client (this corresponds to the classes extending marked as serializable in .NET, and to the valuetypes in CORBA): thus, you need to provide a local implementation for all its methods (idlj just provides an abstract class):

package Ch.Elca.Iiop.Demo.StorageSystem;
public class EntryImpl extends Entry { }

Because Entry has no methods to be implemented(only fields), its implementation is simple and consists of an empty class definition.

Step 6: run the client and the server

As a last step, run the distributed application. First, start the server:

D:\Demo\net:> Server
server running

and then the client:

java -Djava.naming.factory.initial=com.sun.jndi.cosnaming.CNCtxFactory 
         -Djava.naming.provider.url=iiop://localhost:8087 Client

The internet address part of the URL is passed to the JVM in order to tell RMI/IIOP where to find the naming service.

The java client will prompt you for an operation to perform. First input "1" to create a new collection, and then insert a few keys and values, terminate with an empty key. Keep in mind that every command you issue, is executed on the server; in fact, by starting two clients, you will access exactly the same data.

Here's a small session log:

Main Menu:
0. Terminate
1. Create Container
2. Select Container
1

Container Menu:
0. Return to previous menu
1. Set Entry
2. Show Entries
1
Enter an key / value pair:
  key: site
value: CodeProject

Container Menu:
0. Return to previous menu
1. Set Entry
2. Show Entries
1
Enter an key / value pair:
  key: URL
value: http://www.codeproject.com

Container Menu:
0. Return to previous menu
1. Set Entry
2. Show Entries
2
List Entries
  Entry[site] = CodeProject
  Entry[URL] = http://www.codeproject.com

Container Menu:
0. Return to previous menu
1. Set Entry
2. Show Entries
0

Main Menu:
0. Terminate
1. Create Container
2. Select Container
2

Select Containers: enter a list of key / values pairs; terminate with an empty key
  key: site
value: CodeProject
  key:

Matches:

Container 1
List Entries
  Entry[site] = CodeProject
  Entry[URL] = http://www.codeproject.com
Select container number or 0 to return to previous menu
0

Main Menu:
0. Terminate
1. Create Container
2. Select Container
0

            

Conclusions

This article has shown how to access objects created and hosted under .NET from J2EE using IIOP.NET. The implementation of a distributed application is as simple as using only Java's RMI/IIOP. It is obviously possible to work in the opposite way hosting the objects on J2EE and remotely accessing them from .NET: IIOP.NET includes also a generator to create the proxies for .NET given the IDL of the objects.

IIOP.NET allows to transparently access remote objects using the CORBA standard under .NET. It is well integrated in .NET's remoting framework, and as such, that it can be used together with the other remoting channels already available without any code change.

Remoting and RMI are the technologies available in .NET and J2EE to create tightly coupled interaction in a distributed object system. WebServices are a more appropriated for loosely coupled systems.

Links and References

Projects and products:

Technologies:

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Patrik Reali
Web Developer
Switzerland Switzerland
Patrik Reali was a senior software engineer for ELCA Informatique (www.elca.ch) in Zurich, Switzerland; in January 2005, he joined Google. He is specialized in systems and programming languages, with a strong interest for the .NET and Java platforms.

He got a PhD in computer science at ETH-Zurich working on the research operating system and language Oberon.

Together with Dominic Ullmann, he administers the open source project IIOP.NET.

You may also be interested in...

Comments and Discussions

 
GeneralNMAKE Error Pin
saifmasadeh12-Apr-11 6:09
membersaifmasadeh12-Apr-11 6:09 
Generalinvalid character ` in valuetype identifier Pin
Member 14426311-Aug-09 11:39
memberMember 14426311-Aug-09 11:39 
QuestionCan't send objects .Net <-> Java Pin
daJunior10-Jul-08 1:19
memberdaJunior10-Jul-08 1:19 
QuestionAccessing statefull session bean with .NET Pin
grinder12-Dec-07 5:39
membergrinder12-Dec-07 5:39 
GeneralError trying to connect to IIOP.Net object Pin
Paul Janssen23-Jan-07 11:19
memberPaul Janssen23-Jan-07 11:19 
QuestionHow to remove SSL Pin
aveneziano13-Sep-06 7:52
memberaveneziano13-Sep-06 7:52 
QuestionHow to access jacorb-appligator-java-server behind fireware? Pin
jmp0000000016-Aug-06 8:14
memberjmp0000000016-Aug-06 8:14 
QuestionPortableRemoteObject.narrow? Pin
levere16-Aug-06 7:22
memberlevere16-Aug-06 7:22 
Generali have recieved the org.omg.CORBA.MARSHAL exception Pin
zubairy23-Jul-06 23:00
memberzubairy23-Jul-06 23:00 
QuestionHelp Required, client cannot connect to Server[modified] Pin
zubairy20-Jul-06 21:22
memberzubairy20-Jul-06 21:22 
GeneralHelp ACE/TAO idl wstring to CLS string Pin
sbrink201017-May-06 7:39
membersbrink201017-May-06 7:39 
GeneralCannot connect ot ORB Pin
amitaamita19-Dec-05 1:59
memberamitaamita19-Dec-05 1:59 
GeneralRe: Cannot connect ot ORB Pin
balpeckDude10-Jan-06 1:03
memberbalpeckDude10-Jan-06 1:03 
QuestionURGENT....use IIOP.NET with IIS v5.1 and Appserv8.1 ? Pin
d97yer27-Sep-05 4:44
memberd97yer27-Sep-05 4:44 
GeneralNmake fails Pin
bgolda18-Jul-05 5:28
memberbgolda18-Jul-05 5:28 
GeneralRe: Nmake fails Pin
balpeckDude10-Jan-06 1:04
memberbalpeckDude10-Jan-06 1:04 
GeneralRe: Nmake fails Pin
Ayman Nageeb27-Mar-11 3:10
memberAyman Nageeb27-Mar-11 3:10 
GeneralHelp Required Pin
dhaval20126-Jan-04 19:15
sussdhaval20126-Jan-04 19:15 
QuestionWhat about Windows CE? Pin
Serje Schelchkov20-Nov-03 4:12
sussSerje Schelchkov20-Nov-03 4:12 
AnswerRe: What about Windows CE? Pin
Patrik Reali20-Nov-03 5:46
memberPatrik Reali20-Nov-03 5:46 
GeneralRe: What about Windows CE? Pin
Bob1405200229-Sep-04 6:34
memberBob1405200229-Sep-04 6:34 
QuestionCan IIOP.NET use IOR's? Pin
nursed30-Oct-03 4:15
membernursed30-Oct-03 4:15 
AnswerRe: Can IIOP.NET use IOR's? Pin
Patrik Reali2-Nov-03 22:14
memberPatrik Reali2-Nov-03 22:14 
Generaljboss problem Pin
frankie7619-Sep-03 5:07
memberfrankie7619-Sep-03 5:07 
GeneralNew Article: accessing EJBs from .NET with IIOP.NET Pin
Patrik Reali28-Aug-03 22:18
memberPatrik Reali28-Aug-03 22:18 
GeneralRe: New Article: accessing EJBs from .NET with IIOP.NET Pin
Paul Selormey17-Sep-03 21:26
memberPaul Selormey17-Sep-03 21:26 
QuestionFile configuration instead of programmatic? Pin
Andy Neilson29-Jul-03 14:20
memberAndy Neilson29-Jul-03 14:20 
AnswerRe: File configuration instead of programmatic? Pin
Patrik Reali11-Jul-03 5:09
memberPatrik Reali11-Jul-03 5:09 
QuestionRe: File configuration instead of programmatic? [modified] Pin
Joaquim Cardeira29-Jul-06 15:21
memberJoaquim Cardeira29-Jul-06 15:21 
QuestionWhy J# for the IDLToCLS compiler? Pin
Anonymous9-Jul-03 10:38
sussAnonymous9-Jul-03 10:38 
AnswerRe: Why J# for the IDLToCLS compiler? Pin
Dominic Ullmann10-Jul-03 1:10
sussDominic Ullmann10-Jul-03 1:10 
GeneralRe: Why J# for the IDLToCLS compiler? Pin
Paul Bouche13-Aug-04 8:12
sussPaul Bouche13-Aug-04 8:12 
GeneralRe: Why J# for the IDLToCLS compiler? Pin
Dominic Ullmann14-Aug-04 22:34
memberDominic Ullmann14-Aug-04 22:34 
GeneralRe: Why J# for the IDLToCLS compiler? Pin
Paul Bouche16-Aug-04 1:35
sussPaul Bouche16-Aug-04 1:35 
GeneralRe: IIOP.NET and transport security Pin
Dominic Ullmann23-Aug-04 9:51
memberDominic Ullmann23-Aug-04 9:51 
QuestionCan it run using jdk 1.3.1_07? Pin
yossip9-Jul-03 10:28
memberyossip9-Jul-03 10:28 
GeneralMeaning of SOAP.... Pin
Patrik Reali8-Jul-03 2:07
memberPatrik Reali8-Jul-03 2:07 
GeneralRe: Meaning of SOAP.... Pin
ondrejsv15-Jan-06 2:46
memberondrejsv15-Jan-06 2:46 
GeneralClarification: accessing EJB from .NET with IIOP.NET is also possible Pin
Patrik Reali8-Jul-03 0:11
memberPatrik Reali8-Jul-03 0:11 
GeneralRe: Clarification: accessing EJB from .NET with IIOP.NET is also possible Pin
Juerg Staub8-Jul-03 21:30
memberJuerg Staub8-Jul-03 21:30 
GeneralRe: Clarification: accessing EJB from .NET with IIOP.NET is also possible Pin
Patrik Reali8-Jul-03 21:55
memberPatrik Reali8-Jul-03 21:55 
GeneralRe: Clarification: accessing EJB from .NET with IIOP.NET is also possible Pin
Juerg Staub8-Jul-03 22:22
memberJuerg Staub8-Jul-03 22:22 
GeneralRe: Clarification: accessing EJB from .NET with IIOP.NET is also possible Pin
Chris R. West9-Jul-03 7:24
memberChris R. West9-Jul-03 7:24 
GeneralRe: Clarification: accessing EJB from .NET with IIOP.NET is also possible Pin
Juerg Staub9-Jul-03 22:29
memberJuerg Staub9-Jul-03 22:29 
GeneralRe: Clarification: accessing EJB from .NET with IIOP.NET is also possible Pin
Chris R. West9-Jul-03 3:02
memberChris R. West9-Jul-03 3:02 
GeneralRe: Clarification: accessing EJB from .NET with IIOP.NET is also possible Pin
Patrik Reali9-Jul-03 3:38
memberPatrik Reali9-Jul-03 3:38 
GeneralRe: Clarification: accessing EJB from .NET with IIOP.NET is also possible Pin
Juerg Staub9-Jul-03 3:50
memberJuerg Staub9-Jul-03 3:50 
GeneralRe: Clarification: accessing EJB from .NET with IIOP.NET is also possible Pin
Anonymous3-Sep-03 4:05
sussAnonymous3-Sep-03 4:05 
GeneralRe: Clarification: accessing EJB from .NET with IIOP.NET is also possible Pin
Patrik Reali3-Sep-03 21:11
memberPatrik Reali3-Sep-03 21:11 
GeneralFYI Remoting.Corba now has IDL Compiler Pin
Ricky Dhatt2-Jul-03 14:36
sussRicky Dhatt2-Jul-03 14:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150603.1 | Last Updated 2 Jul 2003
Article Copyright 2003 by Patrik Reali
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid