问题描述
我正在使用globus工具包进行项目。在我的服务中,我有一个资源:一个字符串数组。我想从Android客户端获取此资源。我怎样才能做到这一点?如何在wsdl文件中描述字符串数组的类型?
谢谢。
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.
推荐答案
我想你正在寻找这个
<complexType name='ArrayOfString'>
<sequence>
<element name='item' type='xsd:string' maxOccurs='unbounded'/>
</sequence>
</complexType>
资料来源:
更新:
我使用NetBeans 7.0.1进行了测试。结果如下:
I've done a test using NetBeans 7.0.1. The results were this:
声明一个接收String []参数的方法:
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();
}
WSDL为我的方法生成一个带有String数组元素的复杂类型
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>
在客户端中,IDE生成了 List< String>
使用它:
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;
}
}
以及使用服务的方法
private String helloArray(java.util.List<java.lang.String> name) {
edu.home.wsclient.HelloWorldWS port = service.getHelloWorldWSPort();
return port.helloArray(name);
}
我上传了两个项目
这篇关于描述wsdl文件中的字符串数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!