Search code examples
c#.netclientcorbanameservers

How do I look up a Corba service with C# and IIOP.NET?


I am writing a C# client for a Corba server and I am using IIOP.NET, going by the example on the following page: http://iiop-net.sourceforge.net/rmiAdderDNClient.html

I have gotten this far without errors:

// Register channel
IiopClientChannel channel = new IiopClientChannel();
ChannelServices.RegisterChannel(channel, false);

// Access COS naming context
CorbaInit init = CorbaInit.GetInit();
NamingContext context = init.GetNameService(host, port);

The variable "host" is a string with the computer name of the server and "port" is an int representing the port number. The values for these are currently used by other systems to connect to the server so I can confirm that they are correct.

However, trying to connect to the trader service yields an exception in runtime. Here is the code I use to do that:

// Looking up VB Trader
NameComponent[] names = new NameComponent[] { new NameComponent("TraderInterface") };
object obj = context.resolve(names);

And here is the error message I'm getting:

"CORBA system exception : omg.org.CORBA.INV_OBJREF, completed: Completed_No minor: 10102."

This seems to suggest an invalid object reference, but what does that mean? Is the string I am passing to the resolve method incorrectly formatted? I have tried many different names for this service as used in other systems, but I always get the same error, which makes me wonder whether I am even interpreting it correctly.

Incidentally, in my desperation, I have also attempted to obtain an object reference from the IOR, but this again throws a different exception (namely omg.org.CORBA.ORB_package.InvalidName).

OrbServices orb = OrbServices.GetSingleton();
object obj = orb.resolve_initial_references(traderIOR);

Any advice is welcome.


Solution

  • I was never able to reach my server with any of the above methods, however the following code is what finally got the communication working:

    Hashtable props = new Hashtable();
    props[IiopChannel.BIDIR_KEY] = true;
    props[IiopServerChannel.PORT_KEY] = port;
    
    // register corba services
    IiopChannel channel = new IiopChannel(props);
    ChannelServices.RegisterChannel(channel, false);
    
    MyInterface obj = (MyInterface)RemotingServices.Connect(typeof(MyInterface), ior);
    

    I'm not entirely sure why I had to use this (seemingly) unconventional way. Perhaps it is due to the lack of a naming service running on the server. Whatever the cause, I hope this helps somebody out there.