@XmlElement(必填= TRUE)为@WebParam不起作用 [英] @XmlElement(required=true) for @WebParam does not work

查看:3470
本文介绍了@XmlElement(必填= TRUE)为@WebParam不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立使用JAX-WS Web服务。我有一个奇怪的问题,即注释 @XmlElement(必需=真) @WebParam 工作在某些 @WebService 类,但在另外一些国家是行不通的。

I'm building web service using JAX-WS. I have a strange problem that the annotation @XmlElement(required=true) for @WebParam works in some @WebService class, but doesn't work in some others.

我在两个 @WebService 类非常相似code。什么可能会造成这个问题?参数类型或实体类?

I have very similar code in the two @WebService classes. What may cause this problem? Parameter type or the entity class?

编辑:添加样品code

我有两个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方法生成的模式是:

The generated schema for the first web method is:

<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方法生成的模式是:

The generated schema for the second web method is:

<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>

所以第一个工作正常,第二个是行不通的。这怎么可能? (

So the first one works fine, the second one does not work. How is it possible? :(

推荐答案

添加 @XmlElement(必填=真,的nillable = FALSE) @ WebParam 解决我类似的问题。使用CXF 2.7.9。没有尝试把 @XmlElement 第一,会不会是简单的?

Adding @XmlElement(required=true,nillable=false) after @WebParam solved my similar problem. Using CXF 2.7.9. Did not try putting @XmlElement first, could it be that simple?

这篇关于@XmlElement(必填= TRUE)为@WebParam不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆