Why is the serviceName mandatory for javax.xml.ws.Service.create(URL, QName)?
Hi, i've spent a couple of yours in the Java community, was a spec lead for one of our JSRs a while back, also spent some time with Web-Services, and am teaching Java, distributed systems and the lot for over 10 years. So I'll probably not pass as a bloody novice, but still I cannot figure out one recurring and very nagging question when holding lectures about dynamic (i.e. bottom-up) web-service clients:
Why on earth isn't there a javax.xml.ws.Service.create(URL) method, or alternatively, why doesn't javax.xml.ws.Service.create(URL, QName) accept null as a QName, in order to create a dynamic proxy from a WSDL that has exactly one service element, throwing an exception in case it finds more than one?
The method fetches the WSDL from the given location, and inside a WSDL there can be one or more service elements. Clearly, the normal case is that there is exactly one, with more than one service per WSDL being something for prefessionals. So why does the API force a-priori knowledge of something that it can figure out itself 99.9% of the time, i.e. every time a WSDL has exactly one service element? The Metro implementation even lists the valid service names for us in an exception when we pass an invalid name! So why not just choose automatically when there is only one service section in the WSDL whenever there is no contradictory service name specified?
Is this a kind of joke to see how many million hours of wasted beginner's time the API designer can pile up with a single NullPointerException? This one omission means that beginners have to deal uneccessarily with the following technologies, just to create a client for a HelloWorld Web-Service without applying a-priori knowledge about the internals of a WSDL file:
- WSDL basics, Service Names
- QNames and their mapping to qualified Java class names
- Java Reflection (to fetch a package name from a Java service interface, reverse it's components, and build the QName
- The serviceName attribute of the @WebService annotation to force the WebService name to equal the service interface's
All this seems totally unneccessary if there'd be a javax.xml.ws.Service.create(URL), or if javax.xml.ws.Service.create(URL, QName) would accept null to indicate single-service WSDL mode in dynamic proxy generation. Creating a dynamically created client proxy for a simple web-wervice could be as easy as this, with no special knowledge required except how to create a URL:
final Service proxyFactory = Service.create(serviceURL, null);
final MyServiceInterface proxy = proxyFactory.getPort(MyServiceInterface.class);
I understand that this is not a problem for professionals, everyone of us knows to how take a simple look into the WSDL. But we're not beginners. Beginners are drowned in technological detail, especially when it comes to web-services! And here they seem to be drowned for no reason I can figure out, and this at the end of the year 2011!
Does anyone of you have a good answer? I'd be very graceful not having to tell my students again and again that quite a number of Java-Designers was kinda braindead when this was designed and reworked over the years ...
Thanks in advance,
Sascha Baumeister, former spec-lead JSR086