1

How can I make a parameter required for a soap webservice?

@WebService
public class MyService {
    //how can I make city param required?
    @WebMethod
    public ComplexResponse lookup(@WebParam(name = "city") String city) {

    }
}
membersound
  • 81,582
  • 193
  • 585
  • 1,120

1 Answers1

4

Adding

@XmlElement(required=true, nillable=false)

to the param should work:

public ComplexResponse lookup(@WebParam(name = "city") @XmlElement(required=true, nillable=false) String city) 
Juned Ahsan
  • 67,789
  • 12
  • 98
  • 136
  • great, I was not aware one can use `@XmlElement` within the method signature. – membersound Jul 23 '14 at 08:43
  • Note that it requires JAX-B 2.2+. See https://stackoverflow.com/questions/8211420/xmlelement-annotation-dissallowed-with-webparam – Pino May 25 '18 at 13:37