WebSphere Web Services Client for C++, Version 1.0.1 Operating Systems: Linux, Solaris

Array types as output parameters

The prototype method requires an output array to be created. This array must be created and managed properly.

Following on from the example in Array types as input parameters, the following example shows the client application calling the simpleArray method on the web service and using the returned array. The following example shows a typical usage of the method produced by the WSDL example of an array of nillable simple type. The response integer array is not directly accessible. To get the embedded integer array, the user has to call the get method on the piSimpleResponseArray object as follows:

xsd__int_Array *	piSimpleResponseArray = ws.simpleArray( &iInputArray);

int			iSize = 0;	// Size of the array.

// Pointer to a pointer that will contain the array.  Get the contents 
// of the response. The return value will be a pointer to a pointer containing 
// the array and iSize will contain the number of elements in the array.  
// Note that it is a const pointer so cannot be manipulated.
const xsd__int **	ppiIntArray = piSimpleResponseArray->get( (int&) iSize);

// Check if the array size greater than zero before processing it!
if( iSize > 0)
{

// For each element of the array...
for( int iCount = 0 ; iCount < iSize ; iCount++)
   {

// Check that that element is not null before use...
     if( ppiIntArray[iCount] != NULL)
     {
         cout <<“Element[” << iCount << “]=“ << *ppiIntArray[iCount] <<endl;
     }
   }
}

// Later in the code...

delete piSimpleResponseArray;

piSimpleResponseArray = NULL;
Notes:
  1. The returned pointer is not NULL.
  2. The user only needs to delete the object returned by the call to the web service. The client must not delete any object that is extracted from within this object. For example, in the previous code sample, ppiIntArray must not be deleted by the user as it will be deleted by the parent object (piSimpleArrayResponse) when that is deleted.
  3. If the pointer to the array of pointers to integer values (ppiIntArray) is NULL, then this indicates an empty array. If this is the case, iSize is equal to zero.

Reference topic

Terms of Use | Rate this page

Timestamp iconLast updated: 12 Dec 2005
(C) Copyright IBM Corporation 2005. All Rights Reserved.
This information center is powered by Eclipse technology. (http://www.eclipse.org)