引发 CORBA 异常:NotFound

CORBA exception raised: NotFound

您好,我正在尝试使用 docker 实现简单的 client/server CORBA 应用程序。这是 Print.idl 代码:

module Test
{
  interface Printer
  {
    void print();
  };
};

客户端代码如下:

#include <iostream>

#include "PrintC.h"

int main(int argc, char** argv) {
    try {
        CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
        CORBA::Object_var po = orb->string_to_object("corbaname::nameservice/NameService#test/Printer");
        Test::Printer_var p = Test::Printer::_narrow(po.in());
        p->print();
        orb->destroy();
    } catch (CORBA::Exception const& e) {
        std::cerr << "CORBA exception raised: " << e._name() << ": " << e._info().c_str() << '\n';
    }
    return 0;
}

服务器代码如下:

#include <iostream>

#include <orbsvcs/CosNamingC.h>

#include "PrintS.h"

class Implement_Printer : public POA_Test::Printer {
public:
    void print() {
        std:: cout << "Hello World\n";
    }
};

int main(int argc, char** argv) {
    try {
        CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
        CORBA::Object_var object = orb->resolve_initial_references("RootPOA");
        PortableServer::POA_var poa = PortableServer::POA::_narrow(object.in());
        PortableServer::POAManager_var poa_manager = poa->the_POAManager();
        poa_manager->activate();

        Implement_Printer p;    
        Test::Printer_var printer_object = p._this();   
        object = orb->string_to_object("corbaloc::nameservice/NameService");
        CosNaming::NamingContextExt_var naming_context =
        CosNaming::NamingContextExt::_narrow(object.in());
        CosNaming::Name_var name;
        name = naming_context->to_name("test/Printer");
        naming_context->rebind(name.in(), printer_object.in());

        orb->run();

        poa->destroy(1, 1);
        orb->destroy();
    } catch (CORBA::Exception const& e) {
        std::cerr << "CORBA exception raised: " << e;
    }
    return 0;
}

这里是 docker-compose.yml :

version: '3.2'
services:
  serveur:
    image: serveur
    networks:
      - corba
    depends_on:
    - nameservice
  client:
    image: client
    networks:
      - corba
    depends_on:
    - nameservice
    - serveur
  nameservice:
    image: omninames
    networks:
      - corba
networks:
  corba:
    driver: bridge

这是 docker-compose up 的日志:

nameservice_1  | omniNames: (0) 2020-06-10 15:47:16.221353: Data file: '/var/lib/omniorb/omninames-13afbf6c0191.dat'.
nameservice_1  | omniNames: (0) 2020-06-10 15:47:16.221588: Starting omniNames for the first time.
nameservice_1  | omniNames: (0) 2020-06-10 15:47:16.222368: Wrote initial data file '/var/lib/omniorb/omninames-13afbf6c0191.dat'.
nameservice_1  | omniNames: (0) 2020-06-10 15:47:16.222446: Read data file '/var/lib/omniorb/omninames-13afbf6c0191.dat' successfully.
nameservice_1  | omniNames: (0) 2020-06-10 15:47:16.222496: Root context is IOR:010000002b00000049444c3a6f6d672e6f72672f436f734e616d696e672f4e616d696e67436f6e746578744578743a312e300000010000000000000070000000010102000e0000003139322e3136382e3230382e3200f90a0b0000004e616d6553657276696365000300000000000000080000000100000000545441010000001c0000000100000001000100010000000100010509010100010000000901010003545441080000008400e15e01000001
nameservice_1  | omniNames: (0) 2020-06-10 15:47:16.222546: Checkpointing Phase 1: Prepare.
nameservice_1  | omniNames: (0) 2020-06-10 15:47:16.222634: Checkpointing Phase 2: Commit.
nameservice_1  | omniNames: (0) 2020-06-10 15:47:16.222783: Checkpointing completed.
serveur_1      | CORBA exception raised: NotFound (IDL:omg.org/CosNaming/NamingContext/NotFound:1.0)
corba_docker_serveur_1 exited with code 139
corba_docker_client_1 exited with code 139

根据文档,错误是由于 "The Name or one of its components, could not be found. If this exception is raised because the binding already exists or the binding is of the wrong type, the rest_of_name member of the exception has a length of 1."

此代码的灵感来自 https://github.com/cromo/multicontainer-corba/

感谢Wireshark,我得到了更多关于错误的信息。 wireshark

因此它似乎取代了:

name = naming_context->to_name("test/Printer")

来自

name = naming_context->to_name("Printer")

有效。 (客户端代码也是一样)