2011-05-18 100 views
0

這個問題是涉及到另外一個問題與我一直在掙扎指定WCHAR字符串代碼組: How to access CORBA interface without IDL or late-bound invoke remoting methods如何從CORBA客戶端

我真的難倒如何突破這個錯誤有關的代碼集沒有被指定。我一直在追蹤IIOP代碼,試圖找出如何指定CodeSet,並且它看起來可以使用與配置文件關聯的標記組件指定它。對CORBA不熟悉,我不知道標記的組件是什麼或者配置文件是什麼或者如何控制它們,但是我懷疑它可能會受到創建可移植對象攔截器的影響,此時我可以添加標記的CodeSet組件到配置文件,如果這意味着什麼。我只是從我可以從IIOP.NET代碼和Google學到的東西中學習。

有人能幫我理解並希望控制這個嗎?如果服務器是一個黑盒子,而我需要編寫一個客戶端來調用一個輸出字符串的方法,那我該如何告訴IIOP.NET什麼是WChar CodeSet,因此它不會給我一個關於它未指定的錯誤。我嘗試從客戶端OverrideDefaultCharSets,但似乎沒有任何影響。該功能的IIOP示例代碼顯示它正在服務器端使用。

回答

0

這是一個真正痛苦的工作,但我得到了它:

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; 
... 
    } 
在我的情況

不幸的是,問題仍然是字節順序是倒退了,所以我不得不去與一個完全基於只返回字節並手動將它們轉換爲字符串而不是直接獲取字符串的不同解決方案。