1

I wrote a very simple webservice which returns a ArrayList. when I try to test my web service using SOAPUI , the response is empty. I am deploying this application in Tomcat.

Here is my code:

@WebService(endpointInterface = "com.enterprise.ws.WebServiceInterface")
public class WebServiceImpl implements WebServiceInterface{

    @Override
    public ArrayList<String> listSample() {
        // TODO Auto-generated method stub
        ArrayList<String> arrayList = new ArrayList<String>();
        arrayList.add("1212");
        return arrayList;
    }
}

Interface :

@WebService
@SOAPBinding(style = Style.RPC)
public interface WebServiceInterface {

    @WebMethod
    ArrayList<String> listSample();

}

Here is my SOAPUI response .

enter image description here

2
  • Have you tried any other ways to be sure that your service is working as desired before saying that result is not as per the expectations? Commented Aug 14, 2016 at 1:30
  • yes, I have. I have implemented 3 other methods to see if there was an error with the service, The 3 other methods which returns a normal String works fine. Commented Aug 15, 2016 at 17:41

3 Answers 3

1

The problem is probably caused by this JAX-B bug: https://java.net/jira/browse/JAXB-223

The problem is that if you use a JAX-WS 2.0/JAX-B 2.0 you can not use a collection class directly as a return type for a @WebMethod.

There are two possibles workarounds to avoid this issue:

One is to use an Array instead of ArrayList avoiding the use of collection class:

Interface

@WebService
@SOAPBinding(style = Style.RPC)
public interface WebServiceInterface {

    @WebMethod
    String[] listSample();
}

Implementation

@WebService(endpointInterface = "com.enterprise.ws.WebServiceInterface")
public class WebServiceImpl implements WebServiceInterface{

    @Override
    public String[] listSample() {
        return new String[]{"1212"};
    }
}

Another possible workaround is to create a POJO to wrap your ArrayList, and on the @WebMethod return the POJO type instead:

POJO class

public class PojoSample {

     private List<String> listSample;
     // create getters and setters
     ...
}

POJO Interface

@WebService
@SOAPBinding(style = Style.RPC)
public interface WebServiceInterface {

    @WebMethod
    PojoSample listSample();
}

POJO Implementation

@WebService(endpointInterface = "com.enterprise.ws.WebServiceInterface")
public class WebServiceImpl implements WebServiceInterface{

    @Override
    public PojoSample listSample() {
        List<String> arrayList = new ArrayList<String>();
        arrayList.add("1212");

        PojoSample pojo = new PojoSample();
        pojo.setListSample(arrayList);
        return pojo;
    }
}

Hope this helps,

Sign up to request clarification or add additional context in comments.

Comments

1

I Solved that just using the code below

 @WebMethod(operationName = "listarPersonas")
public List<Persona> listarPersonas() {

    return PersonaService.PERSONAS_REGISTRADAS;
}

Just replace List instead Arraylist.

regards;

Comments

0

Try soap binding document with wrapped parameter style insted of RPC binding.

@SOAPBinding(style=Style.DOCUMENT,use=Use.LITERAL, parameterStyle=ParameterStyle.WRAPPED)

With this you can write web method with List return value, or parameter as a List:

@WebMethod
@WebResult(name = "returnName")
public List<MyBean> methodName(@WebParam(name = "paramName") List<ParamBean> paramList);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.