Tuesday, September 14, 2010

metro (JAX-WS 2.2.) web service - down up approach

starting from java code when generating wsdl by using wsgen, I do not see collection elements in XSD (when only getters are used), i.e.

for
public class Cheque implements java.io.Serializable {

Integer id;
Customer customer;
List chequeRows = new ArrayList();

public get List() {
return chequeRows;
}

//no setter for chequeRows is used
//instead getChequeRows().add() is used to add cheque rows to the list
//...
}

and the result xsd does not have chequeRow elements

to force it - annotation @XMLElement is used:

import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlElement;


@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)

public class Cheque implements java.io.Serializable {

@XmlElement
Integer id;

@XmlElement
Customer customer;

@XmlElement
List chequeRows = new ArrayList();

public get List() {
return chequeRows;
}

//no setter for chequeRows is used
//instead getChequeRows().add() is used to add cheque rows to the list
//...
}


also, it is necessary to use @WebParam and @WebResult annotations with name="" otherwise parameters are named 'paramx' and the method result is named 'return';
targetNamespace has to be specified though

No comments:

Post a Comment