WSNewArray

The WSNewArray function creates an array of complex data type objects or primitive values, as defined in the WSDL file for the web service.

You use this function when you are required to pass an array of complex objects or primitives to a web service as message parameters.

Syntax

This function has the following syntax:

Array = WSNewArray(ElementType, ArrayLength)

Parameters

The WSNewArray function has the following parameters:

Table 1. WSNewArray function parameters

Parameter

Format

Description

ElementType

String

Name of the complex object or primitive data type that is defined in the WSDL file. The name format is [Package.]TypeName, where Package is the name of the package you created when you compiled the WSDL file, without the .jar suffix. The package name is required only if you did not previously call the WSSetDefaultPKGName function in the policy.

ArrayLength

Integer

Number of elements in the new array.

Return Value

The WSNewArray returns the new array that is created by the function.

Examples

The following example shows how to use WSNewArray to creates a web services array, where you previously called WSSetDefaultPKGName in the policy. This example creates an array of the data type String as defined in the mompkg.jar file that is compiled from a WSDL file.

// Call WSSetDefaultPKGName

WSSetDefaultPKGName("mompkg");

// Call WSNewArray

MyArray = WSNewArray("String", 4);

The following example shows how to use WSNewArray to create a web services array, where you did not previously call WSSetDefaultPKGName in the policy.

// Call WSNewArray

MyArray = WSNewArray("mompkg.String", 4);
The following example invokes a web service method called runPolicy and passes in a string array as a parameter to the method. The policy creates a WSNewArray object and populates the object with 3 elements. Note that WSNewArray object is used only for arrays of primitives. For arrays of complex types, you need to create a WSNewSubObject for each array element. Also, in general it is easier to use the web services wizard to generate the web services policy from a WSDL, rather than manually creating the web services policy.
RunPolicyDocument=WSNewObject("com.myexample.RunPolicyDocument");
_RunPolicy=WSNewSubObject(RunPolicyDocument,"RunPolicy");

_Arg0=WSNewArray("java.lang.String",3);
_Arg0[0] = 'aaa';
_Arg0[1] = 'bbb';
_Arg0[2] = 'ccc';
_RunPolicy.Arg0Array=_Arg0;

WSParams = {RunPolicyDocument};

WSService = 'MyWebService';
WSEndPoint = 'http://localhost:8888/MyWebService;
WSMethod = 'runPolicy';

WSInvokeDLResult = WSInvokeDL(WSService, WSEndPoint, WSMethod, WSParams);