这个问题与我一直在努力的另一个问题有关: 如何访问corba界面没有IDL或延迟调用remoting方法

我真的很难过如何越过这个错误关于没有指定的代码。我一直在追溯到尝试弄清楚如何指定代码集的IIOP代码,它看起来可以用与配置文件关联的标记组件指定。与CORBA不熟悉,我不知道标记的组件是什么或者配置文件是什么或如何控制它们,但我怀疑它可能会受到创建便携式对象拦截器的影响,我可以添加标记的代码集配置文件的组件,如果这意味着什么。我只是通过我可以从IIOP.NET代码和谷歌学习的内容。

有人可以帮我理解并希望控制这个吗?如果服务器是一个黑匣子,我需要编写一个客户端来调用输出字符串的方法,我如何告诉IIOP.NET要使用的是什么WCHOD代码集所以它不会给我一个关于它未指定的错误。我尝试了来自客户的overrideedefaultCharsets,但似乎没有任何影响。该函数的IIOP示例代码显示它在服务器端使用。

有帮助吗?

解决方案

This was a real pain to work out, but I got it:

class MyOrbInitializer : omg.org.PortableInterceptor.ORBInitializer
{
    public void post_init(omg.org.PortableInterceptor.ORBInitInfo info)
    {
        // Nothing to do
    }

    public void pre_init(omg.org.PortableInterceptor.ORBInitInfo info)
    {
        omg.org.IOP.Codec codec = info.codec_factory.create_codec(
            new omg.org.IOP.Encoding(omg.org.IOP.ENCODING_CDR_ENCAPS.ConstVal, 1, 2));
        Program.m_codec = codec;
    }
}


class Program
{
    public static omg.org.IOP.Codec m_codec;

    static void Main(string[] args)
    {
        IOrbServices orb = OrbServices.GetSingleton();
        orb.OverrideDefaultCharSets(CharSet.UTF8, WCharSet.UTF16);
        orb.RegisterPortableInterceptorInitalizer(new MyOrbInitializer());
        orb.CompleteInterceptorRegistration();
...
        MarshalByRefObject objRef = context.resolve(names);
        string origObjData = orb.object_to_string(objRef);
        Ch.Elca.Iiop.CorbaObjRef.Ior iorObj = new Ch.Elca.Iiop.CorbaObjRef.Ior(origObjData);
        CodeSetComponentData cscd = new CodeSetComponentData(
            (int)Ch.Elca.Iiop.Services.CharSet.UTF8,
            new int[] { (int)Ch.Elca.Iiop.Services.CharSet.UTF8 },
            (int)Ch.Elca.Iiop.Services.WCharSet.UTF16,
            new int[] { (int)Ch.Elca.Iiop.Services.WCharSet.UTF16 });
        omg.org.IOP.TaggedComponent codesetcomp = new omg.org.IOP.TaggedComponent(
            omg.org.IOP.TAG_CODE_SETS.ConstVal, m_codec.encode_value(cscd));
        iorObj.Profiles[0].TaggedComponents.AddComponent(codesetcomp);
        string newObjData = iorObj.ToString();
        MarshalByRefObject newObj = (MarshalByRefObject)orb.string_to_object(newObjData);
        ILicenseInfo li = (ILicenseInfo)newObj;
...
    }

Unfortunately in my case the problem remained that the byte ordering was backwards too, so I had to go with an entirely different solution based on just getting bytes back and manually converting them to a string instead of getting string directly.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top