Пример #1
0
  public static void main(String args[]) {
    try {
      // create and initialize the ORB
      ORB orb = ORB.init(args, null);

      System.out.println("ORB initialised\n");

      // get the root naming context
      org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService");

      // Use NamingContextExt instead of NamingContext,
      // part of the Interoperable naming Service.
      NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);

      // resolve the Object Reference in Naming
      String name = "Hello1";
      helloImpl = HelloHelper.narrow(ncRef.resolve_str(name));

      System.out.println("Obtained a handle on server object: " + helloImpl);
      System.out.println(helloImpl.sayHello());
      helloImpl.shutdown();

    } catch (Exception e) {
      System.out.println("ERROR : " + e);
      e.printStackTrace(System.out);
    }
  } // end main
  public static void main(String args[]) {
    try {
      // 创建和初始化ORB
      ORB orb = ORB.init(args, null);

      // 获得命名服务的Context
      org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService");
      NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);

      // 获得名为“HelloService”的HelloService对象的远程引用
      String name = "HelloService";
      helloServiceImpl = HelloServiceHelper.narrow(ncRef.resolve_str(name));

      // 调用HelloService对象的远程方法
      System.out.println("Obtained a handle on server object: " + helloServiceImpl);
      System.out.println(helloServiceImpl.sayHello());
      helloServiceImpl.shutdown();
    } catch (Exception e) {
      System.out.println("ERROR : " + e);
      e.printStackTrace(System.out);
    }
  }