1

I'm new to web service. I'm writing some simple web services for testing and I have the following questions.

The website here says that JAX-RPC supports array of primitive types. But when I write a simple web service

@WebService
@SOAPBinding(style=Style.RPC)
public interface AddNums {
    @WebMethod
    public int addNumbers(int[] nums);

}

and generate the client code from wsdl i get the following WS client interface.

@WebMethod
@WebResult(partName = "return")
public int addNumbers(
    @WebParam(name = "arg0", partName = "arg0")
    IntArray arg0); 

It generates IntArray class having the member protected List

public class IntArray {

    @XmlElement(nillable = true)
    protected List<Integer> item;

Is this how the arrays are supported? So, the only way to pass the array is to create an instance of IntArray and set List of Integers to it?

Also when i make the webservice to Document style

The WS client interface from WSDL has the following method:

public int addNumbers(
    @WebParam(name = "arg0", targetNamespace = "")
    List<Integer> arg0);

The int[ ] array in the original service, became List< Integer>

Does this mean that Array type in the web service is always converted to List in the client code generated from wsdl?

A--C
  • 36,351
  • 10
  • 106
  • 92
Jack
  • 305
  • 1
  • 3
  • 13

1 Answers1

3

JAX-WS use JAXB to binding. The default mapping for <sequence> is a List. But you can use @XmlJavaTypeAdapter annotation to provide a custom mapping of XML content.

You can see more about JAXB in Introduction to JAXB (The Java Tutorials > Java Architecture for XML Binding (JAXB))

In another hand, you can try returning an array. See the answer for the question I can't return array String[] with JAX-WS. But maybe you should consider: look at this question: Can you return an array from a JAX-WS @WebMethod?.

Community
  • 1
  • 1
Paul Vargas
  • 41,222
  • 15
  • 102
  • 148
  • Thanks a lot for your answer. Could you please answer my other question related to JAX-RPC. The documentation says that JAX-RPC supports Arrays and it doesn't support Collections. But in case of JAX-RPC the int array becomes the class 'IntArray' with a member variable List. – Jack Jan 14 '13 at 06:34