@WebParam的@XmlElement(必需=true)不起作用
2022-09-03 15:27:12
我正在使用 JAX-WS 构建 Web 服务。我有一个奇怪的问题,即注释在某些类中起作用,但在其他一些类中不起作用。@XmlElement(required=true)
@WebParam
@WebService
我在这两个类中有非常相似的代码。什么可能导致此问题?参数类型还是实体类?@WebService
编辑:添加示例代码
我有两个网络服务:
@WebService(name = "ClubMemberPortType", serviceName = "ClubMemberService", portName = "ClubMemberSoapPort", targetNamespace = "http://club.com/api/ws")
public class ClubMemberWS {
@WebMethod(operationName = "findClubMembersByClubId", action = "urn:findClubMembersByClubId")
@WebResult(name = "club_membership")
public List<ClubMembership> findClubMembershipsByClubId(@XmlElement(required=true)
@WebParam(name = "club_id") String clubId,
@WebParam(name = "status") StatusEnum status){
...
}}
和
@WebService(name = "ClubPortType", serviceName = "ClubService", portName = "ClubSoapPort", targetNamespace = "http://club.com/api/ws")
public class ClubWS {
@WebMethod(operationName = "findClubByClubId", action = "urn:findClubByClubId")
@WebResult(name = "club")
public Club findClubByClubId(@XmlElement(required=true)
@WebParam(name = "club_id") String clubId) {
...
}}
为第一个 Web 方法生成的架构是:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://club.com/api/ws">
<soapenv:Header/>
<soapenv:Body>
<ws:findClubMembersByClubId>
<club_id>?</club_id>
<!--Optional:-->
<status>?</status>
</ws:findClubMembersByClubId>
</soapenv:Body>
</soapenv:Envelope>
为第二个 Web 方法生成的架构是:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://club.com/api/ws">
<soapenv:Header/>
<soapenv:Body>
<ws:findClubByClubId>
<!--Optional:-->
<club_id>?</club_id>
</ws:findClubByClubId>
</soapenv:Body>
</soapenv:Envelope>
所以第一个工作正常,第二个不起作用。这怎么可能?:(