Reputation: 1672
Is there any way to make default WSDL being generated by JAX-WS (returned via ?wsdl
) to use XML choice
instead of any
and sequence
?
Upvotes: 4
Views: 1474
Reputation: 2866
I assume you mean the XML schema in the <types/>
part of the WSDL. The generation of this schema is not governed by JAX-WS, but by the JAXB specification. This is the specification for the data binding in JAX-WS.
But to actually answer your question: Yes, you can do that with an appropriate @XMLElements
annotation in the class that represents your datatype. For example, take a web service interface like this:
@WebService
public interface Chooser {
String chooseOne(Choice myChoice);
}
Then the contents of your XSD depend on the structure of the Choice
class. You can force the generation of a choice
element through something like this:
public class Choice {
@XmlElements(value = { @XmlElement(type = First.class),
@XmlElement(type = Second.class) })
private Object myChoice;
}
Classes First
and Second
are possible elements in the choice. The schema generated from this code looks like this:
<xs:complexType name="choice">
<xs:sequence>
<xs:choice minOccurs="0">
<xs:element name="myChoice" type="tns:first"></xs:element>
<xs:element name="myChoice" type="tns:second"></xs:element>
</xs:choice>
</xs:sequence>
</xs:complexType>
This still wraps the choice
in a sequence
, but as there is only one element in the sequence
, this doesn't really matter.
Upvotes: 2