引发的CORBA异常:未找到

问题描述 投票:0回答:1

您好,我正在尝试通过docker实现简单的客户端/服务器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

根据文档,错误是由于“找不到名称或它的组成部分之一。如果由于绑定已经存在或绑定类型错误而引发此异常,则该异常的rest_of_name成员长度为1。“

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

c++ docker docker-compose corba
1个回答
0
投票

感谢Wireshark,我已获得有关该错误的更多信息。wireshark

因此似乎替换了:

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

作者

name = naming_context->to_name("Printer")

作品。 (与客户代码相同)

© www.soinside.com 2019 - 2024. All rights reserved.