【问题标题】:What is the JAX-WS annotation to return an object返回对象的 JAX-WS 注解是什么
【发布时间】:2021-08-23 17:55:39
【问题描述】:

我想将 java 类公开为 JAX-WS 服务。如果我从一个方法返回一个字符串,这很好用,但我不知道如何返回一个对象。查看 Oracle 的示例 (https://docs.oracle.com/middleware/1212/wls/WSGET/jax-ws-examples.htm#WSGET117)
我认为这段代码应该可以工作:

@WebService
public class CCService implements CCServiceLocal {

     /**
     * Default constructor. 
     */
     public CCService() {
     }


    @WebMethod
    @WebResult(name="ApplicationConstantReturnMessage")
    public ApplicationConstant getConst( ) {
        return new ApplicationConstant("Group", "SubGroup", "Id", "Code", "Text", "Description" );
    }

}

但是当我使用 SOAPUi 调用它时,我得到一个空响应:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <getConstResponse xmlns="http://test.cc.com/" xmlns:ns2="http://example.org/complex">
         <ns2:ApplicationConstantReturnMessage/>
      </getConstResponse>
   </soap:Body>
</soap:Envelope>

谁能告诉我我错过了什么?

这是 ApplicationConstant 类:

public class ApplicationConstant {

public  ApplicationConstant(String group, String subGroup, String id, String code, String text, String desc ) {
    this.group = group;
    this.subGroup = subGroup;
    this.id = id;
    this.text = text;
    this.code = code;
    this.desc = desc;
}

public  String group() { return group; }
public  String subGroup() { return subGroup; }
public  String constantIdentifier() { return id; }
public  String constantText() { return text; }
public  String constantCode() { return code; }
public  String constantDesc() { return desc; }


private String group;
private String subGroup;
private String id;
private String text;
private String code;
private String desc;    

}

【问题讨论】:

    标签: java jax-ws


    【解决方案1】:

    好的,我找到了。我需要在 ApplicationConstant 类中添加一些注释,以及默认的无参数构造函数。

    @XmlRootElement(name="ApplicationConstant")
    public class ApplicationConstant {
    
    public ApplicationConstant() {
    }
    
    public  ApplicationConstant(String group, String subGroup, String id, String code, String text, String desc ) {
        this.group = group;
        this.subGroup = subGroup;
        this.id = id;
        this.text = text;
        this.code = code;
        this.desc = desc;
    }
    
    public  String group() { return group; }
    public  String subGroup() { return subGroup; }
    public  String constantIdentifier() { return id; }
    public  String constantText() { return text; }
    public  String constantCode() { return code; }
    public  String constantDesc() { return desc; }
    
    
    @XmlElement private String group;
    @XmlElement private String subGroup;
    @XmlElement private String id;
    @XmlElement private String text;
    @XmlElement private String code;
    @XmlElement private String desc;    
    
    }
    

    【讨论】:

      猜你喜欢
      • 2011-12-26
      • 1970-01-01
      • 2012-10-14
      • 2011-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-25
      • 2023-03-11
      相关资源
      最近更新 更多