Array Result are returned as ComArray objects

Arrays are treated special by the proxy because Arrays cannot be returned as return values from FoxPro functions and so the proxy methods generated by the Wizard cannot return array results from the service directly. Instead any Array return value is returned as in internal ComArray object that has an Instance and Length property.

The returned object can then be used more easily for iterating over items or adding/editing/removing items from the array using the wwDotNetBridge methods to manipulate arrays which require a parent object instance.

A service method call that returns an array might look like this:

DO WebStoreServiceProxy LOCAL loService as WebStoreServiceProxy loService = CREATEOBJECT("WebStoreServiceProxy") *** Service Method Returns an Array of Objects loArrayResult = loService.DownloadInventoryItems("") && ComArray instance returned FOR lnX = 1 TO loArrayResult.Length loItem = loArrayResult.Instance[lnX] && Work with .Instance array property ? loItem.Sku + " " + loItem.Descript + " " + TRANSFORM(loItem.Price) ENDFOR

Note that there's only a single aResult property on the Proxy class which means that if you need to hang on to arrays you should copy them to a private variable or property using ACOPY() as any subsequent array method results will overwrite the aResult property.

Web Service Method Implementation for Array Result Methods

Just for your information Array result methods inject a little extra code into the generated proxy that handles storing of the array into the aResult property.

************************************************************************ * DownloadInventoryItems **************************************** FUNCTION DownloadInventoryItems(Category as String) as wws_itemsRow[] LOCAL loException as Exception, lvResult as Object THIS.lError = .F. this.cErrorMsg = "" lvResult = .F. TRY lvResult = this.oService.DownloadInventoryItems(Category) DIMENSION this.aResult[1] IF ISNULL(lvResult) llError = .T. this.SetError("Result is null") lvResult = -1 ELSE COMARRAY(lvResult,10) ACOPY(lvResult,this.aResult) lvResult = ALEN(lvResult,1) ENDIF CATCH to loException llError = .T. this.cErrorMsg = loException.Message ENDTRY RETURN lvResult ENDFUNC * DownloadInventoryItems

Note that the array is copied and so effectively turned into a native Visual Foxpro array for easier usage. This also means that the array becomes purely read-only and cannot be passed back to .NET as an array.

If you need to pass array data back to .NET you'll need to use wwDotNetBridge's array features to create and add new items.

See also

Accessing Arrays


  Last Updated: 4/17/2009 | © West Wind Technologies, 2009