user3117840
user3117840

Reputation:

How to Create WSDL file to return ArrayList?

I am retrieving data from MySql database as list.My code is When I passed table name it gives list of data based on table name. Now how to create WSDL file to my class.

Below is My code:

@WebService
public class GetEmployeeImpl implements GetEmployee {
EntityManager entityManager = EntityManagerUtil.getEmf().createEntityManager();
@Override
public List getEmployee(String tableName) {

    String tableName1=tableName;
    Query query = entityManager.createNativeQuery("select name,age from "+tableName1);
    List userList =new ArrayList();
    try{
        userList= query.getResultList();            
    }
    catch(Exception e){
        e.printStackTrace();
    }
    return userList;
}

}

Upvotes: 1

Views: 2334

Answers (1)

Cjxcz Odjcayrwl
Cjxcz Odjcayrwl

Reputation: 22847

There's no special Array-like element in WSDL. WSDL describes XML structure, and in XML any child element can appear many times, so to differ between single elements/array you specify the maxOccurs as more than 1:

<xsd:element name="messages" type="xsd:string" maxOccurs="unbounded" minOccurs="0"></xsd:element>

More about creating contract-first services: Writing Contract-First Web Services

Upvotes: 1

Related Questions