11

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?

3
  • Does the VB side have a type library which has DocActionReport contained within it? What is the received type on the VB side (use TypeName) ? Have you created a repro using your own compatible data without calling this.Invoke() ? Commented Jul 13, 2010 at 11:51
  • To answer your questions: Yes, DocActionReport does exist within the type library. the returned type is "Object()" though Object Viewer correctly lists it as "DocActionReport()". I have a .NET client to test the dll and confirm results with and it works as expected. Commented Jul 13, 2010 at 16:15
  • Are you sure the array is not indeed empty? I couldn't reproduce your problem. (Do you even still care about this question at this late date?) Commented Dec 5, 2010 at 1:28

2 Answers 2

1

Here's a trick for you:

  1. Create the exact same interface with a VB6 Com Object
  2. Import that dll into .net
  3. 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.

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 ;)

Sign up to request clarification or add additional context in comments.

1 Comment

I will have to give this a try
0

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.

3 Comments

The web service in question does return XML, but I am not sure how your answer is relevant.
Instead of returning a C# array/list/collection, you can return a string that has an JSON array of objects in it.
it isn't about the transport, but the transform. The proxy is executing and receiving values, so XML and JSON are irrelevant.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.