I am creating a COM Visible C# object to proxy calls to a webservice for VB6 application. I have a method that returns an array of objects.
我正在为VB6应用程序创建一个COM可见c#对象来代理对webservice的调用。我有一个返回对象数组的方法。
public DocActionReport[] DocActionReportByDateRange(System.DateTime reportStartDate, System.DateTime reportEndDate)
{
object[] results = this.Invoke("DocActionReportByDateRange", new object[] {
reportStartDate,
reportEndDate});
return ((DocActionReport[])(results[0]));
}
When I call this method via VB6, like so:
当我通过VB6调用这个方法时,如下所示:
Dim proxy As New QueueMovementServiceClient.ReadQueueInfo
Dim report() As QueueMovementServiceClient.DocActionReport
report = proxy.DocActionReportByDateRange(startDate, reportEndDate)
It successfully executes (I can see that via logging on the web service) but no data is returned to the object in VB6 (LBound(report) == 0, UBound(report) == -1).
它成功执行(通过在web服务上的日志记录可以看到这一点),但是没有数据返回到VB6中的对象(LBound(report) = 0, UBound(report) = -1)。
I have tried a couple of different approaches (changing the method to a void method and passing the collection in as a ref
parameter) but no joy so far.
我尝试了几种不同的方法(将方法改为void方法,并将集合作为ref参数传入),但到目前为止没有什么值得高兴的地方。
What do I need to do to return an array of objects (list, collection, whatever) to a VB6 consumer?
要将对象数组(列表、集合等等)返回给VB6使用者,我需要做什么?
2 个解决方案
#1
1
Here's a trick for you:
这里有一个小技巧:
- Create the exact same interface with a VB6 Com Object
- 使用VB6 Com对象创建完全相同的接口
- Import that dll into .net
- 将那个dll导入。net
- User reflector to look at the generated interop interface, this will hopefull allow you to see what types you need to return, then again you might just get object which won't help at all.
- 用户反射器要查看生成的互操作界面,这将使您能够看到需要返回的类型,然后您可能会得到一个没有任何帮助的对象。
In VB6 if my memory goes back far enough, they used something that still leave me with a nervous twitch called SAFEARRAY's.
在VB6中,如果我的记忆足够久远,他们使用了一种叫SAFEARRAY's的东西,仍然让我神经紧张。
A SAFEARRAY is probably what needs returning here, have a look at this article, I hope it helps you (its the same issue) ...
一个SAFEARRAY可能需要返回这里,看看这篇文章,我希望它能帮助你(它同样的问题)……
How to pass a SAFEARRAY from C# to COM
如何将安全射线从c#传递到COM
After reading about SAFEARRAY's my gut feeling is you will decide to return a string and have toJSON and fromJSON parsers on each side of the call ;)
在阅读了SAFEARRAY的《我的直觉》之后,您将决定返回一个字符串,并在调用的每一端都有toJSON和fromJSON解析器;
#2
0
When calling a WebService all results must by serialized in order to travel through HTTP.
当调用WebService时,所有结果都必须通过序列化才能通过HTTP。
I recommend you to return JSON or XML to make the WebService more interoperable with other platforms.
我建议您返回JSON或XML,以使WebService更能与其他平台互操作。
#1
1
Here's a trick for you:
这里有一个小技巧:
- Create the exact same interface with a VB6 Com Object
- 使用VB6 Com对象创建完全相同的接口
- Import that dll into .net
- 将那个dll导入。net
- User reflector to look at the generated interop interface, this will hopefull allow you to see what types you need to return, then again you might just get object which won't help at all.
- 用户反射器要查看生成的互操作界面,这将使您能够看到需要返回的类型,然后您可能会得到一个没有任何帮助的对象。
In VB6 if my memory goes back far enough, they used something that still leave me with a nervous twitch called SAFEARRAY's.
在VB6中,如果我的记忆足够久远,他们使用了一种叫SAFEARRAY's的东西,仍然让我神经紧张。
A SAFEARRAY is probably what needs returning here, have a look at this article, I hope it helps you (its the same issue) ...
一个SAFEARRAY可能需要返回这里,看看这篇文章,我希望它能帮助你(它同样的问题)……
How to pass a SAFEARRAY from C# to COM
如何将安全射线从c#传递到COM
After reading about SAFEARRAY's my gut feeling is you will decide to return a string and have toJSON and fromJSON parsers on each side of the call ;)
在阅读了SAFEARRAY的《我的直觉》之后,您将决定返回一个字符串,并在调用的每一端都有toJSON和fromJSON解析器;
#2
0
When calling a WebService all results must by serialized in order to travel through HTTP.
当调用WebService时,所有结果都必须通过序列化才能通过HTTP。
I recommend you to return JSON or XML to make the WebService more interoperable with other platforms.
我建议您返回JSON或XML,以使WebService更能与其他平台互操作。