using return values from a c# .net made component build as com+

Posted by YvesR on Stack Overflow See other posts from Stack Overflow or by YvesR
Published on 2011-01-04T12:50:34Z Indexed on 2011/01/04 12:54 UTC
Read the original article Hit count: 388

Filed under:
|
|
|

Hello,

so far I made a component in C# .NET 4 and use System.EnterpriseServices to make it COM visible. I want to develop business methods in C#, but I still need to access them from classic ASP (vbscript).

So far so good, everything works fine (exept function overloading :)). Now I made a test class to get more expirience with return code.

 using System;

using System.Collections.Generic; using System.Linq; using System.Text; using System.EnterpriseServices; using System.Management;

namespace iController { /// /// The tools class provides additional functions for general use in out of context to other classes of the iController. /// public class tools :ServicedComponent {

#region publich methods

public bool TestBoolean()
{
  return true;
}

public string TestString()
{
  return "this is a string";
}

public int TestInteger()
{
  return 32;
}

public double TestDouble()
{
  return 32.32;
}

public float TestFloat()
{
  float ret = 2 ^ 16;
  return ret;
}

public string[] TestArray()
{
  string[] ret = {"0","1"};
  return ret;
}

public int[][] TestJaggedArray()
{
  int[][] jaggedArray = new int[3][];
  jaggedArray[0] = new int[] { 1, 3, 5, 7, 9 };
  jaggedArray[1] = new int[] { 0, 2, 4, 6 };
  jaggedArray[2] = new int[] { 11, 22 };
  return jaggedArray;
}

public Dictionary<string, string> TestDictionary()
{
  Dictionary<string, string> ret = new Dictionary<string,string>();
  ret.Add("test1","val1");
  ret.Add("test2","val2");
  return ret;
}

#endregion

} }

Then I just made a simple vbscript file to run it with cscript.exe for testing porpuse.

Dim oTools : Set oTools = CreateObject("iController.tools")

WScript.StdOut.WriteLine TypeName(oTools.TestBoolean()) & " - " & oTools.TestBoolean() WScript.StdOut.WriteLine TypeName(oTools.TestString()) & " - " & oTools.TestString() WScript.StdOut.WriteLine TypeName(oTools.TestInteger()) & " - " & oTools.TestInteger() WScript.StdOut.WriteLine TypeName(oTools.TestDouble()) & " - " & oTools.TestDouble() WScript.StdOut.WriteLine TypeName(oTools.TestFloat()) & " - " & oTools.TestFloat()

test = oTools.TestArray() WScript.StdOut.WriteLine TypeName(test) WScript.StdOut.WriteLine UBound(test)

For i = 0 To UBound(test) WScript.StdOut.WriteLine test(i) Next

For Each item IN test WScript.StdOut.WriteLine item Next

test = oTools.TestJaggedArray() WScript.StdOut.WriteLine TypeName(test) For Each item IN test WScript.StdOut.WriteLine test & " - " & test.Item(item) Next

test = oTools.TestDictionary() WScript.StdOut.WriteLine TypeName(test) For Each item IN test WScript.StdOut.WriteLine test & " - " & test.Item(item) Next

What works fine: string, int, foat, double

When it comes to array, jaggedarray or dictionaries I get a type mismatch. VarType is 13 object for the dictionary e.g. but this dict seems to be different then the Scripting.Dictionary.

I checked codeproject.com and stackoverflow all day and didn't find any hints exept some thread on stackoverflow where someone mentioned there is a need to created a IDispatch interface.

So anyone ever had the same issue and can help me or give me some hints I can go on with?

© Stack Overflow or respective owner

Related posts about c#

Related posts about asp