我使用Java 8和Eclipse和Tomcat 8 我想写一个SOAP Web服务至极回报3与他们每个人的不同字段名的整数( ID,key和value)是这样的:如何与SOAP在Java中返回多个值(javax.jws中)
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<getArrResponse xmlns="http://DefaultNamespace">
<id>1</id>
<key>1</key>
<value>2</value>
</getArrResponse>
</soapenv:Body>
</soapenv:Envelope>
我写在Java中这个SOAP服务器和它的作品:
@WebService()
public class MyWebService {
@WebMethod(operationName = "printName")
public String printName(@WebParam(name = "userName") String userName) {
return "hello " + userName;
}
@WebMethod
public int[] getArr() {
int[] i = { 1, 1, 2};
return i;
}
}
返回:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<getArrResponse xmlns="http://DefaultNamespace">
<getArrReturn>1</getArrReturn>
<getArrReturn>1</getArrReturn>
<getArrReturn>2</getArrReturn>
</getArrResponse>
</soapenv:Body>
</soapenv:Envelope>
但我不知道,我没有找到如何从getArrReturn变更申请名称ID或关键
编辑: 我试图返回一个Hashtable对象,和它返回:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<getArrResponse xmlns="http://DefaultNamespace">
<getArrReturn>
<item xmlns:ns1="http://xml.apache.org/xml-soap" xmlns="">
<key xsi:type="xsd:string">key</key>
<value xsi:type="xsd:int">1</value>
</item>
<item xmlns="">
<key xsi:type="xsd:string">value</key>
<value xsi:type="xsd:int">2</value>
</item>
<item xmlns="">
<key xsi:type="xsd:string">id</key>
<value xsi:type="xsd:int">1</value>
</item>
</getArrReturn>
</getArrResponse>
</soapenv:Body>
</soapenv:Envelope>
你有没有想过返回一个自定义对象,而不是一个数组的? – azraelAT
我试着返回一个HashTable。但你对“自定义对象”意味着什么? – Army
创建具有3个整数字段(键,值,id)的一类,并返回该类 – azraelAT