2

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>
ThinkingStiff
  • 64,767
  • 30
  • 146
  • 239
Shichao
  • 219
  • 1
  • 3
  • 14

2 Answers2

2

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)
Ascalonian
  • 14,409
  • 18
  • 71
  • 103
  • This solution actually worked for me in my issue I had here: http://stackoverflow.com/questions/10095911/jax-ws-place-a-wrapper-around-an-arraylist-being-returned – Ascalonian Apr 11 '12 at 16:25
0

Annotate your method with:

@WebResult(name="club_membership_list", targetNamespace = "http://club.com/api/ws")
chaplean
  • 197
  • 1
  • 3
  • 10