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?
Java ArrayList of Object Array If you are not sure about the type of objects in the array or you want to create an ArrayList of arrays that can hold multiple types, then you can create an ArrayList of an object array. Below is a simple example showing how to create ArrayList of object arrays in java.
You can call a static method using the class name. Returning an ArrayList from a static method is simple. Create a static method with the return type as ArrayList . Create an ArrayList and instantiate it.
You can just put return null; or return new ArrayList(); since it looks like you don't care with what you're gonna get with the catch. You already have a console log. Save this answer.
The arraylist. c file contains an arraylist implementation. It is implemented as a dynamic array which is automatically resized as needed.
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 ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With