我正在使用JAX-WS構建Web服務。我有一個奇怪的問題,註釋@XmlElement(required=true)
@WebParam
工作在一些@WebService
類,但在其他一些工作。@WebParam的@XmlElement(必需= true)不起作用
我在兩個@WebService
類中有非常相似的代碼。什麼可能導致這個問題?參數類型還是實體類?
編輯:添加代碼示例
我有兩個Web服務:
@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>
所以第一個工作正常,第二個是行不通的。這怎麼可能? :(
這兩種情況的任何代碼示例?您遇到的實際問題(例如,例外情況,對行爲的更好描述等)? –
我已經添加了代碼。 – Shichao
請添加錯誤的堆棧跟蹤 – Tomer