Monday, January 5, 2009

Generating Java clients from WCF web service, trouble with JAXBElement

If you are generating a Java client from WCF service WSDL the result is usually a lot of JAXBElement types instead of simple or complex types defined in the service schema.

While there is nothing wrong with that result, you may want to get rid of most or all of JAXBElements and thus make your code smaller, cleaner and easier to use.

The first solution might seem to be using <xjc:simple/> configuration as shown in http://weblogs.java.net/blog/kohsuke/archive/2006/03/why_does_jaxb_p.html.
It is usually not the case with WCF services and so the <xjc:simple/> method does not help.

The actual solution is found in https://jax-ws.dev.java.net/guide/Customizations_for_WCF_Service_WSDL.html.

Just use generateElementProperty="false".

Quote from the solution:
When processing a WCF service WSDL, it is recommended that the generateElementProperty customization be set to false in <jaxb:globalBindings>


The generateElementProperty attribute was introduced in JAXB 2.1.

No comments: