@XmlElementWrapper 用于使用 JAX-WS 的 Web 方法
我有一个如下所示的 Web 服务,它包含一个将返回对象列表的 Web 方法:
@WebService(name = "ClubMembershipPortType", serviceName = "ClubMembershipService", portName = "ClubMembershipSoapPort", targetNamespace = "http://club.com/api/ws")
public class ClubMembershipWS {
@WebMethod(operationName = "findClubMembershipsByClubId", action = "urn:findClubMembershipsByClubId")
@WebResult(name = "club_membership")
public List<ClubMembership> findClubMembershipsByClubId(@XmlElement(required=true)
@WebParam(name = "club_id") String clubId,
@WebParam(name = "status") StatusEnum status)
...
...
}
}
我收到的 api 请求响应如下所示:
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:findClubMembersByClubIdResponse xmlns:ns2="http://club.com/api/ws">
<club_membership>
...
</club_membership>
<club_membership>
...
</club_membership>
</ns2:findClubMembersByClubIdResponse>
</S:Body>
</S:Envelope>
问题是如何使用 @XmlElementWrapper
(或其他方式?)做出如下响应?
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:findClubMembersByClubIdResponse xmlns:ns2="http://club.com/api/ws">
<club_membership_list>
<club_membership>
...
</club_membership>
<club_membership>
...
</club_membership>
</club_membership_list>
</ns2:findClubMembersByClubIdResponse>
</S:Body>
</S:Envelope>
I have a web service like below, it contains a web method which will return a list of objects:
@WebService(name = "ClubMembershipPortType", serviceName = "ClubMembershipService", portName = "ClubMembershipSoapPort", targetNamespace = "http://club.com/api/ws")
public class ClubMembershipWS {
@WebMethod(operationName = "findClubMembershipsByClubId", action = "urn:findClubMembershipsByClubId")
@WebResult(name = "club_membership")
public List<ClubMembership> findClubMembershipsByClubId(@XmlElement(required=true)
@WebParam(name = "club_id") String clubId,
@WebParam(name = "status") StatusEnum status)
...
...
}
}
The response I got for the api request is like below:
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:findClubMembersByClubIdResponse xmlns:ns2="http://club.com/api/ws">
<club_membership>
...
</club_membership>
<club_membership>
...
</club_membership>
</ns2:findClubMembersByClubIdResponse>
</S:Body>
</S:Envelope>
The question is how to use @XmlElementWrapper
(or other way?) to make the response like below?
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:findClubMembersByClubIdResponse xmlns:ns2="http://club.com/api/ws">
<club_membership_list>
<club_membership>
...
</club_membership>
<club_membership>
...
</club_membership>
</club_membership_list>
</ns2:findClubMembersByClubIdResponse>
</S:Body>
</S:Envelope>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你尝试过这个吗?
Did you try this?
用以下方式注释你的方法:
Annotate your method with: