@WebParam 的 @XmlElement(required=true) 不起作用 [英] @XmlElement(required=true) for @WebParam does not work

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

问题描述

我正在使用 JAX-WS 构建 Web 服务.我有一个奇怪的问题,@WebParam 的注释 @XmlElement(required=true) 在某些 @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 类中有非常相似的代码.什么可能导致这个问题?参数类型还是实体类?

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

添加示例代码

我有两个网络服务:

@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? :(

推荐答案

Adding @XmlElement(required=true,nillable=false) after @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?

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

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