Accessing the servant object

Why and when to perform this task

Use this task to add code to the source file for a CORBA client and get access to the servant object that is created by the CORBA server and bound into the name space. The client code gets access to the servant object by creating a ::CosNaming::Name that specifies the full name of the object from the root naming context.

For the example code in this task, the CORBA server created the servant object called servantObject1 in a new context, servantContext. servantContext is bound to the domain naming context, which is bound to the root naming context. Therefore, the full name for the servant object, from the root naming context, is domain.servantContext.servantObject1.

Steps for this task

  1. Edit the client source file client.cpp
  2. In this client source file, add code to the main() function to get a new ::CosNaming::Name for the servant object and to look up the servant object with that name in the name space. For an example, see the following code:
    // Get the root naming context.
      rootNameContext = get_naming_context();
      if ( ::CORBA::is_nil( rootNameContext ) )
        exit( -1 );
    
      // Find the servant_Impl created by the server. Look up the
      // object using the complex name of domain.servantContext.servantObject1,
      // which is its full name from the root naming context, as created
      // by the server.
      //Note: The actual complex name may vary.
      //Run the command WAS_HOME/bin/dumpNameSpace to identify
      //the exact name of your servant object.
      try
      {
        // Create a new ::CosNaming::Name to pass to resolve().
        // Construct it as the full three-part complex name.
        ::CosNaming::Name servantName; 
        servantName.length( 3 ); 
        servantName[0].id = ::CORBA::string_dup( "domain" ); 
        servantName[0].kind = ::CORBA::string_dup(""); 
        servantName[1].id = ::CORBA::string_dup( "servantContext" ); 
        servantName[1].kind = ::CORBA::string_dup( "" ); 
        servantName[2].id = ::CORBA::string_dup( "servantObject1" ); 
        servantName[2].kind = ::CORBA::string_dup( "" ); 
        ::CORBA::Object_ptr objPtr = rootNameContext->resolve(servantName);
      }
    
      // catch exceptions ...
    

Results

This task adds code that enables a CORBA client to find the specified servant object (created by a CORBA server) in the system name space.

What to do next

Add code to the client source file to enable the client to call methods on the servant object as described in Adding code to call methods on the servant object. For related information on accessing the servant object, see Servant object access

Related concepts
Servant object access
Related tasks
Creating the CORBA client main code (client.cpp)
Invoking methods on the servant object



Searchable topic ID:   tcor_pgmc1e
Last updated: Jun 21, 2007 8:07:48 PM CDT    WebSphere Business Integration Server Foundation, Version 5.0.2
http://publib.boulder.ibm.com/infocenter/wasinfo/index.jsp?topic=/com.ibm.wasee.doc/info/ee/corba/tasks/tcor_pgmc1e.html

Library | Support | Terms of Use | Feedback