When complex types are used in a web service, the same rules as for simple types apply.
The following example shows classes produced from WSDL with a complex type. As shown in this example, complex types only take shallow copies of the data when using the set and get methods.
class STORAGE_CLASS_INFO ComplexType { public: class xsd__string Message; class xsd__int MessageSize; xsd__string getMessage(); void setMessage( xsd__string InValue); xsd__int getMessageSize(); void setMessageSize( xsd__int InValue);
The client has to remember that when using pointers to objects, only the pointer is copied and it is not cloned. For example, if a complex type contains a string, the client can set the contents of the string by creating a local string and then using the set method on the complex object to copy that string into the object.
The following example shows restrictions that can be applied when using a complex type:
xsd__int iStringLength = strlen( “Hello World”); xsd_string myNewString = new char[iStringLength + 1]; strcpy( myNewString, “Hello World”); myComplexType.setMessage( myNewString); delete myNewString; // Do this and myComplexType.Message will be left pointing to // invalid memory.
Alternatively:
delete myComplexType; // Do this and myNewMessage will be pointing to invalid memory.
The same rules as for simple types apply to the parameters of a complex type when used on a method call. These rules are as follows:
ComplexType * myNewComplexType = new ComplexType( myExistingComplexType);
then this takes a deep copy of all the member variables from the original object to populate the new object.
If a WSDL describes a complex type being used within an array, the WSDL2Ws tool generates a corresponding array object using the complex name type suffixed with "_Array".