.net - CORBA IIOPNet 和 OmniORBpy,带有值类型参数的远程方法调用问题

标签 .net python corba iiop

我的范围:我正在尝试为两个应用程序创建一个 CORBA 解决方案,一个在 .NET 端(服务器),另一个在 python(客户端)。我使用 IIOPNet 生成服务器和 IDL,使用 OmniORBpy 生成 stub 和客户端调用。通常适用于简单的调用,例如典型示例:Adder。但是,当我尝试使用自定义类调用方法时,它不起作用。

我在服务器端有这个类(我的删除对象)要从客户端调用:

public class MyRemoteObject : MarshalByRefObject
{
    public override object InitializeLifetimeService()
    {
        return null;
    }

    public bool DoSomething(InterfaceRequest requestData)
    {
        return true;
    }

}

输入参数类类型在服务器端声明如下(非常简单):
[Serializable]    
public class InterfaceRequest
{
    public int SiteId;
    public int UserId;
}

我使用 CLSIDLGenerator 生成我的 IDL,然后使用我的 python stub (如“omniidl -bpython -CPython ...”),直到这里一切正常。

所以我启动服务器(VS调试环境),现在在我的客户端代码上我解析服务名称,我成功缩小了我的远程对象并创建了我的请求对象但是当我尝试这样做时:
request = InterfaceRequest()
request.SiteId = 1
request.UserId = 3

result = remoteObj.DoSomething(request) 

Python 在没有任何警告、没有异常(exception)、任何类型的消息的情况下爆炸,(我将omniORB 配置文件上的跟踪标签更新为最高 [40] 但没有被跟踪),它只是崩溃了,我尝试了很多东西我总是得到相同的结果。问题当然与参数有关(我猜)。

我正在像这样运行客户端:
python client.py -ORBInitRef NameService=corbaname::localhost:8087

(我的最后一种方法:python 对象引用架构和按值传递的符合值类型参数在某些时候不匹配)

技术细节: NET 4.0、IIOPNet(最后一个)、Python 2.6、omniORB-4.1.5、omniORBpy-3.5。

感谢您的每一个帮助,我对此有点坚持,谢谢。

是的,为 MyRemoteObject 生成的 IDL 是这个:
......
module module1 {
module module2 {
module module3 {
module module4 {

interface MyRemoteObject {

boolean TestConnection(in double value) 
raises (::Ch::Elca::Iiop::GenericUserException);

bool DoSomenthing(in ::module1::module2::module3::InterfaceRequest requestData) 
raises (::Ch::Elca::Iiop::GenericUserException);
};

......

但是既然您提到了这一点,我只是注意到在同一个文件(myRemoteObject.idl)上,我有一个表示 InterfaceRequest 类型的结构,但像这样为空:
module module1 {
module module2 {
module module3 {

valuetype InterfaceRequest;

};
};
};

当然,我会在其他地方生成具有正确内容的 IDL:
valuetype InterfaceRequest {
public long SiteId;
public long UserId;
};

奇怪,也许是我生成这些东西的顺序,这很重要吗?,显然这里有问题,对吧?

最后,我的这两个类(远程和参数类型)的 python stub 看起来像这样:
class _objref_MyRemoteObject (CORBA.Object):
    _NP_RepositoryId = MyRemoteObject._NP_RepositoryId

    def __init__(self):
        CORBA.Object.__init__(self)

    def TestConnection(self, *args):
        return _omnipy.invoke(self, "TestConnection", _0_module1.module2.module3.module4.MyRemoteObject._d_TestConnection, args)

    def DoSomething(self, *args):
        return _omnipy.invoke(self, "DoSomething", _0_module1.module2.module3.module4.MyRemoteObject._d_DoSomething, args)

    __methods__ = ["TestConnection", "DoSomething"] + CORBA.Object.__methods__

和接口(interface)请求:
class InterfaceRequest (_0_CORBA.ValueBase):
    _NP_RepositoryId = "IDL:module1/module2/module3/InterfaceRequest:1.0"

    def __init__(self, *args, **kwargs):
        if args:
            if len(args) != 2:
                raise TypeError("InterfaceRequest() takes 2 arguments "
                                "(%d given)" % len(args))
            self.SiteId = args[0]
            self.UserId = args[1]
        if kwargs:
            self.__dict__.update(kwargs)

因此,即使最后 IDL 不太正确(只是猜测),python stub 也会生成正确的内容和正确的路径。

感谢您的帮助(我已更改真实姓名,希望 id 无关紧要)并且对这么大的帖子感到抱歉。

最佳答案

我认为您忘记添加由 IDLCompiler 生成的接口(interface) stub 。

public class MyRemoteObject : MarshalByRefObject, module1.module2.module3.MyRemoteObject
{
    public override object InitializeLifetimeService()
    {
        return null;
    }

    public bool DoSomething(InterfaceRequest requestData)
    {
        return true;
    }    
}

您需要使用以下规则在 C# 中实现 valuetype:
[现在不是你的错误,但你迟早会得到这个错误]。
  • 你确实实现了一个类 XYZImpl,其中 XYZ 是 valuetype
  • 的类型名称
  • XYZImpl 继承自抽象类 XYZ(该类由 IDLToCLS 生成器生成)
  • XYZImpl 与 XYZ
  • 位于同一命名空间中
  • XYZImpl 可序列化
  • XYZImpl 有一个无参数的公共(public)构造函数
  • XYZImpl 不是抽象的
  • XYZImpl 实现了所有继承的抽象方法和属性
    Link

  • 请记住,您需要打开一个 IIOPServerChannel 执行以下操作:
    int port = 0;
    IiopChannel chan = new IiopChannel(port);
    ChannelServices.RegisterChannel(chan);
    

    关于.net - CORBA IIOPNet 和 OmniORBpy,带有值类型参数的远程方法调用问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7239257/

    相关文章:

    c# - C# 中的空 "if"语句是否会导致错误或警告?

    c# - 并行事件订阅者 .net 4.5

    python - 如何在 PyQt5 Qwidget 上显示 matplotlib

    python - 在 Python 中对 Corba 进行单元测试

    c# - log4net依赖问题

    c# - .NET - 将语句 lambda 主体转储到字符串

    python - 通过 python paramiko 使用本地参数在 ssh 连接上执行受限远程脚本

    python - .NET Core 2.0 和 Angular 初始应用程序构建失败 - 找不到 python 后跟 JavaScript 运行时错误

    java - 如何使用 IP 将远程客户端连接到 java 中的 corba 服务器?

    java - org.omg.CORBA.TRANSIENT : initial and forwarded IOR inaccessible vmcid: IBM minor code: E07 from IIB application