2011-09-08 57 views
0

我從經典的asp調用C#com interop dll。將字典對象從傳統ASP傳遞到C#

我想發送名稱值對的C#DLL。

嘗試使用經典asp中的字典對象,並在C#中使用相同的字典對象(scripting.runtime com reference)接受它。

但它給出了無效的過程調用或參數錯誤。

我有這個想法的Scripting.Dictionary使用從這個鏈接 http://www.eggheadcafe.com/community/aspnet/2/10016705/is-there-any-way-to-pass-a-dictionary-object-to-c.aspx

可能是即時通訊失去了一些東西

問題

  1. 的我缺少的東西或者是有更好的辦法將Classic asp的關鍵值 對傳遞給C#。
  2. 我還在考慮在C#中使用此庫asp3tojson和 反序列化。它太複雜了嗎?

回答

1

我會將它轉換爲JSON。至少要知道沒有對象級別的互操作性問題,特別是在混合各種MS對象時。

+0

謝謝。讓我試試這個 –

+0

你可以推薦一個好的庫來將經典的asp字典對象轉換爲json。 asp3json似乎不適用於我 –

+0

您可能需要遍歷字典並將JSON構建爲字符串。這可能有所幫助:http://stackoverflow.com/questions/2789830/iterate-through-a-vb6-dictionary –

1

嗨。可以在asp經典應用程序中使用System.Collections.HashTable和許多其他來自mscorlib)。
請嘗試以下操作。希望有用。
天冬氨酸應用:

Option Explicit 
Dim Dictionary, objNetCom, i 

Set Dictionary = Server.CreateObject("System.Collections.HashTable") 
Set objNetCom = Server.CreateObject("MyTest.doTest") 

With Dictionary 
    For i = 65 To 90 
     .Add Chr(i), i 
    Next 
End With 
Response.Write objNetCom.getDictType(Dictionary) 

Set Dictionary = Nothing 
Set objNetCom = Nothing 

一個C#的COM可見:

using System; 
using System.Collections; 

namespace MyTest 
{ 
    public class doTest 
    { 
     public string getDictType(Object tDict) 
     { 
      return String.Format("Type : \"{0}\", Count : {1}", ((Hashtable)tDict).GetType().ToString(), ((Hashtable)tDict).Count); 
     } 
    } 
}