我正在尝试通过首先创建 java 类来使用自下而上的方法创建 Web 服务。我的实现如下所示:
@WebMethod(operationName = "addNumbers")
public String addNumbers(
@WebParam(name = "addNumberRequest") @XmlElement(required = true, nillable = false) final AddNumberRequest addNumberRequest) {
return "Hello World";
}
AddNumberRequest 类如下:
@Repository
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(propOrder = { "number1", "number2", "number3" })
public class AddNumberRequest {
private int number1;
private int number2;
private int number3;
public int getNumber1() {
return number1;
}
public void setNumber1(int number1) {
this.number1 = number1;
}
public int getNumber2() {
return number2;
}
public void setNumber2(int number2) {
this.number2 = number2;
}
public int getNumber3() {
return number3;
}
public void setNumber3(int number3) {
this.number3 = number3;
}
}
Web 服务已发布,但当我从 soapui 生成示例请求时,请求如下所示:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.service.test.com/">
<soapenv:Header/>
<soapenv:Body>
<ws:addNumbers>
<addNumberRequest>
<number1>?</number1>
<number2>?</number2>
<number3>?</number3>
</addNumberRequest>
</ws:addNumbers>
</soapenv:Body>
</soapenv:Envelope>
有没有办法简单地通过使用注释来创建该方法的 java 实现,以便示例请求如下所示:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.service.test.com/">
<soapenv:Header/>
<soapenv:Body>
<addNumberRequest>
<number1>?</number1>
<number2>?</number2>
<number3>?</number3>
</addNumberRequest>
</soapenv:Body>
</soapenv:Envelope>
我希望能够确定包装器元素的名称,例如 addNumberRequest 根本没有 ws:addNumbers (默认情况下由 operationName 生成)元素。