If you created your client file with the CORBA template, ClientMain, instead of generating a client-side file with the CORBA wizard, you must add code to your file. The code you add to your client program depends on the binding method the program uses:
The CORBA lookup() method uses the NameComponent object to construct the name associated with the object reference. This name is passed to the resolve() method, which returns the CORBA object. If your client class uses Naming Service Binding, the generated code does not include the lookup() method. To code the method, you need to know how the server binds itself to the naming service. The easiest way to generate this code is with the Naming Service browser, which can read the server's IOR from the naming service and generate lookup code for you.
To code the resolve() method:
// resolve names with the Naming Service // paste code retrieved using the Copy Client/Server Code action // (on the corresponding node in the Naming Service Browser) here
String[] client_name_hierarchy = new String [] {"JDK", "Naming"};
Whichever binding method your client uses, the result is an object of type org.omg.CORBA.Object, named obj, which represents the IOR. For example, clients that read an IOR from a file contain this
In clients that use naming service binding, the IOR is obtained by the resolve() method. See the for details.
To use the IOR, you need to call a narrow() method, which returns the object reference.
To code the narrow() method:
/*interface_name*/ srv = /*interface_name*/Helper.narrow (obj);
helloworld.HelloApp.Hello srv = helloworld.HelloApp.HelloHelper.narrow (obj);
You can add code at the end of the client file to call server-side methods. Look for the comment:
// add your client code hereand type in your code below that line.
The last step is to compile together all of the classes related to the client, including the IDL file:
See also | |
---|---|
Completing Server-Side Files
Generating CORBA Files |