Web服务模式给出了一个java类 [英] Web Service Schema given a java class
问题描述
我是网络服务的新手,我正在探讨有关此主题的一个特定想法。
I am new to web service and I am exploring one particular idea regarding this topic.
假设我有一个类似下面的java类
Supposed I have a java class like below
public class Department{
private int id;
private String name
private List<Employee> employees;
//getters and setters
}
我想创建一个Web服务方法,我希望它在我调用此Web服务时公开数据
以遵循某个模式。这基本上是
是SOAP响应模式。
I want to create a Web Service method and I wanted it to expose the data to follow a certain schema when I call this web service. This will basically be the SOAP response schema.
<department>
<id />
<name />
<employees type="list">
<employee>
<emp_id />
<name />
</employee>
.
.
</employees>
</department>
Web服务方法只会找到一个给出部门ID输入参数的部门。
输出应遵循上面的模式
The web service method will just find a department given a department id input parameter. The output should follow the schema above
@WebService
public class Service{
@WebMethod
public Department getDepartment(int id){
//code
}
}
这可能吗?
推荐答案
您需要使用正确的JAXB注释来注释您的POJO类。
You need to annotate your POJO class with proper JAXB annotations.
以下是一个例子:
@XmlAccessorType(value = XmlAccessType.NONE)
public class Department {
@XmlElement
private Long id
@XmlElement
private String name
@XmlElement
private List<Employee> employees;
// +accessor methods
}
也以相同的方式注释您的Employee类。
Also annotate your Employee class in the same manner.
并使用
@WebService(name = "departmentServiceSOAP", targetNamespace = "/namespace")
@javax.jws.soap.SOAPBinding(style = SOAPBinding.Style.DOCUMENT, use = SOAPBinding.Use.LITERAL, parameterStyle = SOAPBinding.ParameterStyle.WRAPPED)
public interface DepartmentService {
@WebMethod
public Department getDepartment(Long id);
}
- 参考
- Reference
这篇关于Web服务模式给出了一个java类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!