【发布时间】: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;
}
【问题讨论】: