【问题标题】:Returning Pojo WebService JaxWS. Renaming <return> node返回 Pojo WebService JaxWS。重命名 <return> 节点
【发布时间】:2012-08-29 00:26:06
【问题描述】:

我认为这应该很容易,但我真的无法让它发挥作用。

我正在从 WebMethod 返回一个 Pojo:

@WebMethod
public SubCategoria getSubCategorias() throws JAXBException {

    SubCategoria a = subCategoriaEJB.getAllSubCategorias().get(1);

    return a;
}

我只是退回第一个,试试看。

我正在使用soapUI 来测试我的Ws。

回复是:

    <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
       <S:Body>
          <ns2:getSubCategoriasResponse xmlns:ns2="http://webService/">
             <return>
                <categoria>
                   <descripcion>Categoria Unica</descripcion>
                   <idCategoria>1</idCategoria>
                </categoria>
                <descripcion>asd123213</descripcion>
                <idSubCategoria>2</idSubCategoria>
             </return>
          </ns2:getSubCategoriasResponse>
       </S:Body>
    </S:Envelope>

我希望将“返回”节点称为“子类别”。我不能真正使它与 XmlRootElement 注释一起使用。

这是我的 Pojo(子类别)

    package ejb.Entidades;

    import javax.persistence.Entity;
    import javax.persistence.Id;
    import javax.persistence.ManyToOne;
    import javax.xml.bind.annotation.XmlRootElement;


    @Entity
    @XmlRootElement(name="SubCategoria")
    public class SubCategoria {

        @Id
        private Integer idSubCategoria;

        @ManyToOne 
        private Categoria categoria;


        private String descripcion;


        public Integer getIdSubCategoria() {
            return idSubCategoria;
        }
        public void setIdSubCategoria(Integer idSubCategoria) {
            this.idSubCategoria = idSubCategoria;
        }

        public String getDescripcion() {
            return descripcion;
        }
        public void setDescripcion(String descripcion) {
            this.descripcion = descripcion;
        }
        public Categoria getCategoria() {
            return categoria;
        }
        public void setCategoria(Categoria categoria) {
            this.categoria = categoria;
        }

    }

有人知道吗?

提前致谢。

【问题讨论】:

    标签: web-services jaxb jax-ws pojo


    【解决方案1】:

    你应该使用@WebResult注解:

    @WebMethod
    @WebResult(name = "subCategoria")
    public SubCategoria getSubCategorias() throws JAXBException {
    
        SubCategoria a = subCategoriaEJB.getAllSubCategorias().get(1);
    
        return a;
    }
    

    【讨论】:

    • Tibtof,谢谢。抱歉这么晚才回复。我正在旅行并停止在这个项目中工作。干杯。
    猜你喜欢
    • 2013-08-07
    • 1970-01-01
    • 2013-12-31
    • 1970-01-01
    • 1970-01-01
    • 2011-08-10
    • 1970-01-01
    • 2023-04-04
    • 1970-01-01
    相关资源
    最近更新 更多