return 对象的 JAX-WS 注释是什么
What is the JAX-WS annotation to return an object
我想公开一个 java class 作为 JAX-WS 服务。如果我从一个方法 return 一个字符串,这很好用,但我不知道如何 return 一个对象。查看 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 class:
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;
}
好的,我找到了。我需要在我的 ApplicationConstant class 中添加一些注释,以及一个默认的无参数构造函数。
@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;
}
我想公开一个 java class 作为 JAX-WS 服务。如果我从一个方法 return 一个字符串,这很好用,但我不知道如何 return 一个对象。查看 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 class:
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;
}
好的,我找到了。我需要在我的 ApplicationConstant class 中添加一些注释,以及一个默认的无参数构造函数。
@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;
}