web services - How return multiple values with SOAP in Java (javax.jws) -
web services - How return multiple values with SOAP in Java (javax.jws) -
i'm using java 8 , eclipse tomcat 8. want write soap web service wich homecoming 3 integer each of them different field name (id, key , value) :
<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>
i wrote soap server in java , works :
@webservice() public class mywebservice { @webmethod(operationname = "printname") public string printname(@webparam(name = "username") string username) { homecoming "hello " + username; } @webmethod public int[] getarr() { int[] = { 1, 1, 2}; homecoming i; } }
it returns :
<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>
but don't know , don't found how alter filed name getarrreturn id or key
edit : tried homecoming hashtable object, , returned :
<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>
you should seek create , homecoming class jaxb annotations this:
@xmlaccessortype(xmlaccesstype.field) @xmltype(name = "", proporder = { "context", "key", "value" }) @xmlrootelement(name = "getarrresponse") public class getarrresponse implements serializable { private final static long serialversionuid = 1l; @xmlelement(name = "id", required = true) private int id; @xmlelement(name = "key", required = true) private int key; @xmlelement(name = "value", required = true) private int value; }
usually more convenient generate such classes xsd, consider if you're going create more complex service.
java web-services soap
Comments
Post a Comment