如何使用 C# 和 IIOP.NET 查找 Corba 服务?
Posted
技术标签:
【中文标题】如何使用 C# 和 IIOP.NET 查找 Corba 服务?【英文标题】:How do I look up a Corba service with C# and IIOP.NET? 【发布时间】:2012-05-21 07:53:47 【问题描述】:我正在为 Corba 服务器编写 C# 客户端,并且我正在使用 IIOP.NET,通过下一页上的示例进行操作:http://iiop-net.sourceforge.net/rmiAdderDNClient.html
我已经走到了这一步,没有错误:
// Register channel
IiopClientChannel channel = new IiopClientChannel();
ChannelServices.RegisterChannel(channel, false);
// Access COS naming context
CorbaInit init = CorbaInit.GetInit();
NamingContext context = init.GetNameService(host, port);
变量“host”是一个带有服务器计算机名称的字符串,“port”是一个表示端口号的 int。这些值当前被其他系统用于连接到服务器,因此我可以确认它们是正确的。
但是,尝试连接到交易者服务会在运行时产生异常。这是我用来执行此操作的代码:
// Looking up VB Trader
NameComponent[] names = new NameComponent[] new NameComponent("TraderInterface") ;
object obj = context.resolve(names);
这是我收到的错误消息:
“CORBA 系统异常:omg.org.CORBA.INV_OBJREF,已完成:Completed_No minor:10102。”
这似乎暗示了一个无效的对象引用,但这是什么意思?我传递给解析方法的字符串格式是否不正确?我尝试了许多其他系统中使用的该服务的不同名称,但我总是得到相同的错误,这让我怀疑我是否正确解释它。
顺便说一句,在我绝望的情况下,我还尝试从 IOR 获取对象引用,但这又引发了一个不同的异常(即 omg.org.CORBA.ORB_package.InvalidName)。
OrbServices orb = OrbServices.GetSingleton();
object obj = orb.resolve_initial_references(traderIOR);
欢迎任何建议。
【问题讨论】:
【参考方案1】:我无法使用上述任何一种方法访问我的服务器,但是以下代码最终使通信正常工作:
Hashtable props = new Hashtable();
props[IiopChannel.BIDIR_KEY] = true;
props[IiopServerChannel.PORT_KEY] = port;
// register corba services
IiopChannel channel = new IiopChannel(props);
ChannelServices.RegisterChannel(channel, false);
MyInterface obj = (MyInterface)RemotingServices.Connect(typeof(MyInterface), ior);
我不完全确定为什么我必须使用这种(看似)非常规的方式。可能是由于缺少在服务器上运行的命名服务。不管是什么原因,我希望这对那里的人有所帮助。
【讨论】:
以上是关于如何使用 C# 和 IIOP.NET 查找 Corba 服务?的主要内容,如果未能解决你的问题,请参考以下文章