2011-09-08 84 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); 
     } 
    } 
}