如何将对象的数组/列表/集合从 C# 返回到 VB6
我正在创建一个 COM Visible C# 对象来代理对 VB6 应用程序的 Web 服务的调用。我有一个返回对象数组的方法。
public DocActionReport[] DocActionReportByDateRange(System.DateTime reportStartDate, System.DateTime reportEndDate)
{
object[] results = this.Invoke("DocActionReportByDateRange", new object[] {
reportStartDate,
reportEndDate});
return ((DocActionReport[])(results[0]));
}
当我通过 VB6 调用此方法时,如下所示:
Dim proxy As New QueueMovementServiceClient.ReadQueueInfo
Dim report() As QueueMovementServiceClient.DocActionReport
report = proxy.DocActionReportByDateRange(startDate, reportEndDate)
它成功执行(我可以通过登录 Web 服务看到),但没有数据返回到 VB6 中的对象 (LBound(report) == 0, UBound(报告)== -1
)。
我尝试了几种不同的方法(将方法更改为 void 方法并将集合作为 ref 参数传递),但到目前为止没有任何乐趣。
我需要做什么才能将对象数组(列表、集合等)返回给 VB6 使用者?
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.
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:
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
).
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.
What do I need to do to return an array of objects (list, collection, whatever) to a VB6 consumer?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这里有一个技巧给你:
在 VB6 中,如果我的记忆足够久远的话,他们使用了一种叫做 SAFEARRAY 的东西,它仍然让我感到紧张。
SAFEARRAY 可能是这里需要返回的内容,看看这篇文章,我希望它能帮助您(它是同一个问题)...
如何将 SAFEARRAY 从 C# 传递到 COM
阅读有关 SAFEARRAY 的内容后,我的直觉是您将决定返回一个字符串并拥有 toJSON 和 fromJSON 解析器在通话的每一方;)
Here's a trick for you:
In VB6 if my memory goes back far enough, they used something that still leave me with a nervous twitch called 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) ...
How to pass a SAFEARRAY from C# to 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 ;)
调用 WebService 时,所有结果都必须序列化才能通过 HTTP 传输。
我建议您返回 JSON 或 XML 以使 WebService 与其他平台的互操作性更强。
When calling a WebService all results must by serialized in order to travel through HTTP.
I recommend you to return JSON or XML to make the WebService more interoperable with other platforms.