Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WSDL to Java or Java to WSDL?

I've recently picked up a project which has a rather nasty build process. Hand coded XSD schemas are read by JAXB to generate a Java model of classes and factories, which is used in hand coded Java web service classes (annotated), which are then deployed to a server, which is used as a source to read the complete WSDLs from in order to generate a second Java based model which includes the service and factory classes for the complete WSDL, which is used in client programs.

This sounds aweful and I don't think I need it to be so complicated so at some stage I'd like to chuck all this away and either

  • Hand craft the WSDLs, generate a full model and add service code.
  • Or - Write the service and model classes and generate WSDLs as necessary on the server at run time.

Either way I want to end up with one source base for the model which both the server and clients can use and have one "source of truth" for what the model should be, where as at the moment I feel like I have several.

At the moment I'm leaning towards the second option, but which would you choose? And which technologies would you use?

like image 969
drekka Avatar asked Mar 16 '11 05:03

drekka


People also ask

What is WSDL to Java?

In Java Web Development World, WSDL is an XML format for describing network services as a set of endpoints operating on messages containing either document-oriented or procedure-oriented information.

How do you convert WSDL to Java classes?

If you would like to parse a WSDL file to generate java classes, you can use the wsimport tool. This 'wsimport' tool comes with the JDK (Java Development Kit) and resides in the JDK bin directory.

How is WSDL file generated in Java?

Create a WSDL descriptor from Java code Select the desired class name in the editor. In the main menu, go to Tools | XML WebServices and WSDL | Generate WSDL From Java Code. In the Generate WSDL From Java dialog that opens, specify the following: The name and URL address of the Web service.


2 Answers

In the project I'm working on, we're currently redoing our web services completely. These services offer server functionalities to clients via SOAP. From what I've learned looking at all the intricacies of that protocol, which highly affect the layout of the WSDL, I'd rather not write a WSDL myself. There are so many things you can get wrong (especially when it comes to things like parameter style and all that). And once your WSDL "is out there" and clients generated from that WSDL are happily communicating with your application you can no longer change it again (or you start thinking about a versioning strategy, which can turn out to be quite painful as well).

So my strong suggestion is to write your service code in Java and let your library generate a WSDL for you. You can then very easily play around with different binding styles (which in turn affect interoperability with other clients). A very thorough article describing all of that can be found here:

http://www.ibm.com/developerworks/webservices/library/ws-whichwsdl/

Additionally, WSDLs are not particularly readable for humans and therefore (at least in my view) harder to maintain by humans. Java code on the other hand is fairly easy to read (or at least you can write it that way) which is a even better reason to handcraft the Java code and not the WSDL.

Hope that helps in making your decision.

like image 176
RobertB Avatar answered Sep 23 '22 14:09

RobertB


The cleanest method is to generate the WSDL manually or using a designer - and from them generate the proxies and stubs.

The logic behind this way, is that the WSDL defines the service contract, which should be implementation agnostic - And the Java classes are implementation specific - and those implementation details are often transfered to the WSDL

The exact problems depends on the Java to WSDL convertor you use (or more importantly, the Java to XSD converter) - but they are pretty common, especially if you plan to add non Java servers or clients in you environment.

If you prefer writing the services in Java, you should follow some guidelines that will minimize implementation lock in, like:

  • control the translation from classes to XSD (I believe this can be done using annotations
  • use only simple types and aggregates of simple types as parameters (don't pass your regular classes as parameters)
like image 31
Ophir Yoktan Avatar answered Sep 19 '22 14:09

Ophir Yoktan