Sunday, December 18, 2011

JAX-WS: WSDL Fetched During Service Proxy Creation

I did some webservice client programming again lately, and was surprised to learn that by default, the JAX-WS service client library fetches the WSDL from its original location again each time a service proxy is created. I am pretty sure that not everyone is aware of that, and that this leads to production system problems once WSDLs become unavailable.

The JAX-WS FAQs mention runtime binding as the reason behind this, but as the WSDL is not supposed to change, I wonder why it isn't simply mapped into a generated Java class, or added as a local resource. Anyway, this can be done manually using the JAX WS wsgen tool (commandline option "-wsdl"), adding the local WSDL file to your JAR file, and then setting the service proxy's WSDL_LOCATION constant to:
MYSERVICE_WSDL_LOCATION = 
new URL(
MyClass.class.getResource(""),
"MyWsdl.wsdl");