I'm using the globus toolkit for a project. In my service i have a resource: a string array. I want to get this resource from an Android client. How can I do that? How can I describe in the wsdl file the type "array of string"? Thank you.
Asked
Active
Viewed 2.5k times
3 Answers
6
I guess you're looking for this
<complexType name='ArrayOfString'>
<sequence>
<element name='item' type='xsd:string' maxOccurs='unbounded'/>
</sequence>
</complexType>
Source: http://www.activebpel.org/samples/samples-2/BPEL_Samples/Resources/Docs/arrays.html
UPDATE:
I've done a test using NetBeans 7.0.1. The results were this:
Declare a method that receives a String[] parameter:
@WebMethod(operationName = "helloArray")
public String helloArray(@WebParam(name = "name") String[] name) {
StringBuilder sb = new StringBuilder("Hello ");
if (name != null) {
for(int i = 0; i < name.length; i++) {
sb.append(name[i]);
if (i < (name.length - 1)) {
sb.append(" and ");
}
}
}
sb.append('!');
return sb.toString();
}
The WSDL generated a complex type for my method with a String array element
<xs:complexType name="helloArray">
<xs:sequence>
<xs:element name="name" type="xs:string" nillable="true" minOccurs="0"
maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
In the client, the IDE generated a List<String>
to consume it:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "helloArray", propOrder = {"name"})
public class HelloArray {
@XmlElement(nillable = true)
protected List<String> name;
public List<String> getName() {
if (name == null) {
name = new ArrayList<String>();
}
return this.name;
}
}
And a method to consume the service
private String helloArray(java.util.List<java.lang.String> name) {
edu.home.wsclient.HelloWorldWS port = service.getHelloWorldWSPort();
return port.helloArray(name);
}
I've uploaded both projects in this address

Luiggi Mendoza
- 85,076
- 16
- 154
- 332
-
Thank you. Now when I get the response from the client, as a generic Java object, and I try to cast it to a (String []) I get a ClassCastException. – Matteo Reda May 07 '12 at 14:03
-
I also get an Exception in validating the wsdl: ArrayOfString is referenced but not defined! – Matteo Reda May 07 '12 at 14:12
-
is this in the WSDL or in a XSD file? – Luiggi Mendoza May 07 '12 at 14:19
-
when I call the getClass() method on the response it returns me java.lang.String. I wonder why! – Matteo Reda May 07 '12 at 15:42
1
You can use a custom type which has a String element (and more data, if you'd like) with multiplicity > 1.
<xsd:sequence>
<xsd:element name="YourClass" type="pre:YourClass" maxOccurs="unbounded" minOccurs="0">
</xsd:element>
</xsd:sequence>

Jeff Allen
- 17,277
- 8
- 49
- 70
-
How do I cast the Object returned by the response? If I try with (String []) I get a ClassCastException. – Matteo Reda May 07 '12 at 15:29
0
Have the XML call out a parent tag with multiple children, each with one string value from your array:
<parent>
<child>String 1</child>
<child>String 2</child>
</parent>
Name the tags appropriately.

duffymo
- 305,152
- 44
- 369
- 561