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>
1
  • by the way, i saw some related post here
    – Shichao
    Oct 23, 2011 at 23:49

2 Answers 2

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)
1
0

Annotate your method with:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.