Instantiation using the naming service API

Obtaining proxies for CosNaming and SessionManager interfaces

To instantiate a proxy using the CORBA naming service API, you need to generate proxies for the naming service interface and include these proxies in the library list for the client. Use the EAServer Proxy wizard to create a proxy project for the CosNaming module, build the project to create a proxy library, and add the proxy library to the client target’s library list. You also need a proxy for the SessionManager module.

Getting an initial naming context

After initializing the ORB, call the Resolve_Initial_References function to obtain an initial naming context and use _Narrow to convert it to a reference to the CORBA naming context interface. You must identify the CosNaming package by including omg.orb in the class name as shown in the example below.

Resolving the naming context

You need to resolve the naming context to obtain a reference to a Factory object for the component and then narrow that reference to the SessionManager::Factory interface. The resolve method takes a name parameter, which is a sequence of NameComponent structures. Each NameComponent structure has an id attribute that identifies the component and a kind attribute that can be used to describe the component. In the example below, the name has only one component.

Creating a reference to the component’s interface

Call the create method of the Factory object to obtain proxies for the component. The create method returns a CORBA object reference that you can convert into a reference to the component’s interface using the _Narrow function.

Example

The NamingContext and NameComponent types used in the example are proxies imported from the CosNaming package in EAServer, and the Factory type is imported from the SessionManager package:

CORBAObject my_corbaobj
JaguarORB my_orb
NamingContext my_nc
NameComponent the_name[]
Factory my_Factory
n_jagcomp my_jagcomp

my_orb = CREATE JaguarORB
// Enclose the name of the URL in single quotes
my_orb.init("ORBNameServiceURL='iiop://server1:2000'")

my_orb.Resolve_Initial_References("NameService", &
	my_corbaobj)
my_corbaobj._narrow(my_nc, &
	"omg.org/CosNaming/NamingContext")

the_name[1].id = "mypackage/n_jagcomp"
the_name[1].kind = ""

my_corbaobj = my_nc.resolve(the_name)
my_corbaobj._narrow(my_Factory, &
	"SessionManager/Factory")
my_corbaobj = my_Factory.create("admin","")
my_corbaobj._narrow(my_jagcomp,
	"mypackage/n_jagcomp")

my_jagcomp.getdata()