Going for the full geek posting here, as I mentioned earlier in the week, I’m doing a lot of web services work at the moment. One of the requirements of one of the services is to return an array of complex objects (as opposed to an array of strings for example). The objects get described by the WSDL for serialization but it took me a little while to work out how to actually write the code to return the array…
public class MyService{
public ComplexType[] getList(String in){
ArrayList retList = new ArrayList();
//…
//Build ArrayList Here
//…
return (ComplexType[])retList.toArray(new ComplexType[retList.size()]);
}
}
I’m sure it’s pretty obvious to most people, but the fact that you have to convert the ArrayList to an array and then also cast it to an array of the correct type was what had confused me. Anyway it’s all working now, which is nice!
Umm. I use a slightly simpler method:
class returnClass
public myArray() as whatever…
sub new()
end sub
end class
class actualWebService
public function returnAnArray() as returnClass
‘ create a new instance of return class here
set returnAnArray = myNewInstanceOfReturnClass
end function
end class
I’m a simple soul me.
Nothing to stop you nesting classes – so that you have a complex multi-value class containing other classes, etc.. We use this to pass back our request class, which then contains profile classes, etc, etc.
—* Bill