我正在研究SOAP WS,并且创建了一个非常简单的 类,我将其公开为Web服务。SOAP响应模式
@WebService
public class StudentWS {
@WebMethod
public Student getStudent(){
Student stud = new Student();
stud.setId(99);
stud.setFirstName("John");
stud.setLastName("Doe");
stud.setGpa(2.1);
return stud;
}
}
当我把这个Web服务,返回的SOAP响应如下 这种格式。
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:getStudentResponse xmlns:ns2="http://annotation/">
<return>
<firstName>John</firstName>
<gpa>2.1</gpa>
<id>99</id>
<lastName>Doe</lastName>
</return>
</ns2:getStudentResponse>
</S:Body>
</S:Envelope>
我的问题是,是否有某种方式可以影响SOAP响应,以遵循如下所示的某种架构。
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:getStudentResponse xmlns:ns2="http://annotation/">
<student gpa="2.1">
<id>99</id>
<name>
<firstName></firstName>
<lastName></lastName>
</name>
</student>
</ns2:getStudentResponse>
</S:Body>
</S:Envelope>
我的数据来自于像这样的POJO类。
@XmlRootElement
public class Student {
private int id;
private String firstName;
private String lastName;
private double gpa;
//getters and setters
}
谢谢。