Shichao
Shichao

Reputation: 219

@XmlElementWrapper for web method using JAX-WS

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>

Upvotes: 2

Views: 3806

Answers (2)

chaplean
chaplean

Reputation: 197

Annotate your method with:

@WebResult(name="club_membership_list", targetNamespace = "http://club.com/api/ws")

Upvotes: 0

Ascalonian
Ascalonian

Reputation: 15193

Did you try this?

@XmlElementWrapper(name="club_membership_list", required=true)  
@XmlElement(name="club_membership", required=true) 
public List<ClubMembership> findClubMembershipsByClubId(@WebParam(name = "club_id") String clubId, 
@WebParam(name = "status") StatusEnum status)

Upvotes: 2

Related Questions