2011-07-04 51 views
4

我想從c#返回一個數組到傳統的asp使用com。 This post helped me lot,但我仍然有問題:返回數組從C#到經典ASP與COM

我在C#下面的方法:

public object[] returnStuff() { 
    return new object[] {'1','2','3'}; 
} 

我的經典ASP:

dim responseArray1 

responseArray1 = RegusSoapComponent.returnStuff() 

response.write("Type of Array one is " & VarType(responseArray1)) 
response.write("Type of Array one is " & responseArray1(1)) 

我的輸出是:

response is Type of Array one is 8204 

Microsoft VBScript運行時錯誤'800a01ca'

變量使用VBScript中

不支持自動化類型無論我做什麼,我似乎不能夠訪問這個變量。

+0

嘗試返回新對象[3] {'1','2','3'}; ? – Gage

+0

@Gage:在運行時不會有任何區別。 – SLaks

+0

@SLaks,我認爲它不會,但那是我看到他和他發佈的例子之間唯一的區別。 – Gage

回答

4

VBScript喜歡收到包含變體safearray的變體。所以你需要返回一個包裝你的對象數組的對象。例如:

public object returnStuff() { 
    return new object[] {'1','2','3'}; 
} 

應該以正確的方式編組。詳細版本見a previous answer