Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Passing arrays to .NET and getting arrays back
Message
 
À
02/05/2011 12:02:48
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Versions des environnements
Visual FoxPro:
VFP 9 SP2
Divers
Thread ID:
01509041
Message ID:
01509326
Vues:
61
Charles,

The error you're getting appears to be occurring in the .NET code, not the VFP code.

FWIW, receiving arrays is easy - passing arrays back, especially if they need to be typed is often not possible at all.

FWIW, working with .NET arrays in VFP sucks and some scenarios don't work at all. It's totally impossible to pass an array of typed objects back to .NET because VFP mangles any .NET object when it is turned into a FoxPro array. What you get on the client is a FoxPro array not a .NET array. So it's also not directly possible to modify a .NET array and pass it back if you modify the structure of the array itself in any way.

For what it's worth you might want to check into wwDotNetBridge, which addresses a lot of the array pain by providing helper methods to access arrays while keeping them in .NET and not converting them to the funky FoxPro arrays that mangle the .NET logistics.

Here are two topics from the Help File:

http://www.west-wind.com/webconnection/docs?page=_2rv0njk2g.htm

and

http://www.west-wind.com/webconnection/docs?page=_2940qmjs8.htm

Note the samples use wwDotnetBridge to load the .NET object without COM registration, but if you want you can also load your .NET COM object directly via CREATEOBJECT() to get the base object reference - it works both ways.You also don't need to deal with object[] arrays - you can use any type. One limitation is that it's limited to 1 dimensional arrays.

The idea of all this is that the array isn't passed to VFP - it stays in .NET and you manipulate that array in .NET. Only when you retrieve an item does data come out of .NET. This avoids the whole issue of array craziness that goes with Interop.

Also, if you're calling a simple SOAP 1.x Web Service the Web Service Proxy generator will create a FoxPro proxy for you and it will automatically use wwDotNetBridge for service calls. So when a service method returns an array you get back a ComArray instance or when you get back a DataSet you get back an XmlAdapter etc. - auto type fix up. Might be worth it for you to check out since y

Hope this helps,

+++ Rick ---






>update: have found this
>http://www.west-wind.com/weblog/posts/2006/Jul/27/Passing-Arrays-between-FoxPro-and-NET-with-COM-Interop
>and am working through it now. Will return with further confusion <g>
>
>
>I have built a webservice wrapper in C# for VFP to eat. Works great. All my exposed methods are receiving and returning to and from VFP as expected - except arrays
>
>I think I need a refresher on the nuances of passing arrays in and out. Because of lack of strong typing, I assume the .NET incoming param must be object[] or object[,]
>
>I am currently trying to pass in a vfp @arrparam where arrparam is dime arrayparam[4] of strings. I would like to get back ids[4,2] with strings and integers.
>
>I could also pass in a 2 dime array by reference if I could figure out how to pass it back.
>
>If my object is lows, besides
>
>comarray(lows,0) to get the array to pass in 0 based what are the other tricks I should know about this?
>
>The method works fine in my .NET test harness
>
>
>    public object[,] FindIdsByEmails(object[] emailarray)
>        {
>            int emailslen = emailarray.Length;
>            object[,] returnarray = new object[emailslen, 2];
>            for (int i = 0; i < emailslen; i++)
>            {
>                string email = (string)emailarray[i];
>                long? id = this.FindIdByEmail(email);
>                returnarray[i, 0] = email;
>                if (id != null)
>                {
>                    returnarray[i, 1] = id;
>                }
>                else
>                {
>                    returnarray[i, 1] = 00000;
>                }
>            }
>            return returnarray;
>        }
>
>
>But this VFP test prg gets me an error that "Function argument value, type or count is invalid."
>
>
>CD "c:\users\pagan\documents\visual studio 2010\projects\glwebservice\glwebservice\bin\debug"
>ACTIVATE WINDOW watch
>lows = CREATEOBJECT("glwebservice.glclient")
>lows.login("xxxxxx@xxxxx.org", "password", "<security key")
>
>DIMENSION foo(4)
>
>foo(1)="dan@primarydatasolutions.com"
>foo(2)="charleshankey@f1tech.com"
>foo(3) = "raferris@hsonline.net"
>foo(4) = "foo@foo.net"
>DIMENSION ids(4,2)
>
>comarray(lows,0)
>
>* here's where I get the error
>
>ids = lows.FindIdsByEmails(@foo)  
>
>lows.logout
>lows = null
>
>RETURN
>
>
>
>
>Suggestions, hints, pointing to docs all appreciated.
+++ Rick ---

West Wind Technologies
Maui, Hawaii

west-wind.com/
West Wind Message Board
Rick's Web Log
Markdown Monster
---
Making waves on the Web

Where do you want to surf today?
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform