Hello.idl
#ifndef __HELLO_DEFINED
#define __HELLO_DEFINED
/* CmIdentification
%X% %Q% %Z% %W% */
interface Hello {
/*
@roseuid 445956A100BB */
string sayHello (
in string str
);
};
#endif
###################################################################################
java server端实现文件:(idlj -fall hello.idl生成文件生成的文件略)
import org.omg.CORBA.ORB;
public class HelloImpl extends HelloPOA {
private ORB orb;
public void setORB(ORB orb_val) {
orb = orb_val;
}
/* 实现接口声明方法sayHello */
public String sayHello(String message) {
System.out.println("我在CORBA的服务器端,客户端正在调用'sayHello'方法. ");
System.out.println("Hello " + message);
return message;
}
}
####################################################################
C客户端(omniidl -bcxx SysProp.idl 生成的文件略)
#include <iostream.h>
#include "Hello.h"
//-ORBInitRef NameService=corbaloc::168.192.1.213:1050/NameService
int main(int argc, char** argv)
{
try {
CORBA::ORB_var orb = CORBA::ORB_init(argc, argv, "omniORB4");
CORBA::Object_var obj = orb->resolve_initial_references("NameService");
CosNaming::NamingContext_var rootContext;
rootContext = CosNaming::NamingContext::_narrow(obj.in());
CosNaming::Name name;
name.length(1);
name[0].id = (const char*) "Hello";
name[0].kind = (const char*) "";
CORBA::Object_var obj1= rootContext->resolve(name);
Hello_ptr echoref =Hello::_narrow(obj1);
if( CORBA::is_nil(echoref) ) {
cerr << "没有对象" << endl;
return 1;
}
const char* message="hhhheeeeeereeeeeeeeeeee";
CORBA::String_var dest = echoref->sayHello(message);
cout << (char*)message << "=" <<(char*)dest << endl;
orb->destroy();
}
catch(CORBA::COMM_FAILURE& ex) {
cerr << "Caught system exception COMM_FAILURE -- unable to contact the "
<< "object." << endl;
}
catch(CORBA::SystemException&) {
cerr << "Caught CORBA::SystemException." << endl;
}
catch(CORBA::Exception&) {
cerr << "Caught CORBA::Exception." << endl;
}
catch(omniORB::fatalException& fe) {
cerr << "Caught omniORB::fatalException:" << endl;
cerr << " file: " << fe.file() << endl;
cerr << " line: " << fe.line() << endl;
cerr << " mesg: " << fe.errmsg() << endl;
}
catch(...) {
cerr << "Caught unknown exception." << endl;
}
return 0;
}
VC6运行时的参数 -ORBInitRef NameService=corbaloc::168.192.1.213:1050/NameService