Showing posts with label web services. Show all posts
Showing posts with label web services. Show all posts

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.

Friday, February 8, 2008

Having trouble with SOAP headers and JAX-WS RI?

There are many WSDLs out there that define SOAP headers in binding section, but not in portType section. More often than not this is not intentional (mostly found in .NET generated WSDLs) and can cause unwanted side effects. One of these effects is that JAX-WS RI wsimport tool won't generate header parameters for operations.

As a solution you can always cast your port object to WSBindingProvider and use setOutboundHeader function, but that's a bit messy. JAX-WS documentation goes even further saying that "The portable way of doing this is that you create a SOAPHandler and mess with SAAJ". Ugh, not good.

But there is one simple, clean and easy solution. If you are using JAX-WS RI 2.1.3 (released December 18, 2007, Metro 1.1 includes it) or newer then wsimport has a new option: -XadditionalHeaders. Use this option when you have a WSDL with additional headers that are not part of portType contract.