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:
1 |
CORBAObject my_corbaobj<br>JaguarORB my_orb<br>NamingContext my_nc<br>NameComponent the_name[]<br>Factory my_Factory<br>n_jagcomp my_jagcomp<br> <br>my_orb = CREATE JaguarORB<br>// Enclose the name of the URL in single quotes<br>my_orb.init("ORBNameServiceURL='iiop://server1:2000'")<br> <br>my_orb.<span>Resolve_Initial_References</span>("NameService", &<br> my_corbaobj)<br>my_corbaobj._narrow(my_nc, &<br> "omg.org/CosNaming/NamingContext")<br> <br>the_name[1].id = "mypackage/n_jagcomp"<br>the_name[1].kind = ""<br> <br>my_corbaobj = my_nc.resolve(the_name)<br>my_corbaobj._narrow(my_Factory, &<br> "SessionManager/Factory")<br>my_corbaobj = my_Factory.create("admin","")<br>my_corbaobj._narrow(my_jagcomp,<br> "mypackage/n_jagcomp")<br> <br>my_jagcomp.getdata() |