@XmlElement(required=true) for @WebParam does not work

前端 未结 5 677
情歌与酒
情歌与酒 2020-12-31 05:27

I\'m building web service using JAX-WS. I have a strange problem that the annotation @XmlElement(required=true) for @WebParam works in some @

相关标签:
5条回答
  • 2020-12-31 05:54

    You try change the order in @WebParam and @XmlElement? actually i have a WS whit this:

    public Persona consultarPersona(@WebParam(name = "cedula") @XmlElement(required=true, nillable=false, name="cedula", namespace="cedulaParam")  String cedula) 
    

    And the description generate is:

     <xsd:schema>
    <xsd:import namespace="cedulaParam" schemaLocation="http://eniacstein-pc:8080/WSDL_Sample/GestorPersonas?xsd=2"/>
    </xsd:schema>
    

    and the schema definition:

        <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0" targetNamespace="cedulaParam">
    <xs:element name="cedula" type="xs:string"/>
    </xs:schema>
    

    that's it!!

    0 讨论(0)
  • 2020-12-31 05:59

    I have same problem. I found solution in using of separate class for parameters of service method.

    e.g.

    @XmlType(name="SampleRequestType", propOrder={"title", "ref"})
    public class SampleRequest {
        @XmlElement(name="title", required=false)
        private String title;
        @XmlElement(name="ref", required=true)
        private String ref;
        ...
    

    web-method

    @WebMethod
    public String sampleMethod(@WebParam(name = "params") SampleRequest params) {
    

    maybe this will help

    0 讨论(0)
  • 2020-12-31 06:00

    Perhaps I found the solution. If anyone encounters the same problem, just place these annotations in you web service contract(interface) in exact this order, as all guys answered before.

    @WebParam(name = "yourParam") @XmlElement(required = true)  YourParam param
    
    0 讨论(0)
  • 2020-12-31 06:01

    Adding @XmlElement(required=true,nillable=false) after @WebParam solved my similar problem. Using CXF 2.7.9. Did not try putting @XmlElement first, could it be that simple?

    0 讨论(0)
  • 2020-12-31 06:10

    If you are having the following error message: "The annotation @XmlElement is disallowed for this location", chances are you're using the wrong import statement.

    Change it to:

    import javax.xml.bind.annotation.XmlElement;
    

    As Eclipse suggests another package as the first option, it's a very common mistake.

    0 讨论(0)
提交回复
热议问题