Sunday, March 13, 2011

When “WSDL First”? When “Java First”? Where do we “Meet in the Middle”?

In most of the books that I have read on JAX-WS, JAX-RPC or any other on Java Web Services, one of the initial chapters is inadvertently based on "the different approaches to developing services", discussing Java or WSDL First approach. What I have always found unsatisfying about these chapters is the fact that they talk of how we can create/implement such methodologies, but, never about why or even when we use which approach? This article I try to explain when and why do we use the different approaches rather than how do we use them.

For the purpose of discussion let us consider the following case study.

    "An online book store wants to expose its products as a service. It would be offering search services to any customer that maybe interested in looking up data about the books that it has in stock. The book store sells Books and Periodicals"

Data to be exposed
BooksPeriodicals
TitleTitle
NameName
Publishing HousePublishing House
AuthorEditor
Revision NumberPrint Date


Business View:

In the above table, it is evident that according to the business, a book and a periodical are 2 totally different entities. Conceptually also a book is a onetime published entity while a periodical is a regularly published entity. They have different business significance and probably different business sections. So when the business team tries to visualize a Book or a Periodical in a web service, they see it as an xml with the below defined attributes:

 <Book>  
   <title></title>  
   <name></name>  
   <publishingHouse></publishingHouse>  
   <author></author>  
   <revisionNumber></revisionNumber>  
 </Book>  
 <Periodicals>  
   <title></title>  
   <name></name>  
   <publishingHouse></publishingHouse>  
   <editor></editor>  
   <printDate></printDate>  
 </Periodicals>  

Architect/Technical View:

When an architect or a technical designer is asked to look at the same problem given above, he will try to apply all the principles of OOP and create a design solution that looks like the one give below:



As shown above, the use inheritance to extract out the common properties by creating a base class and then extending the base class to create the actual classes of Books and Periodicals; is one of the first solutions provided. This extraction probably also has ramifications on the signature and number of methods exposed.

It must be noted that both the views are correct and proper. The Business is trying to visualize a solution that is more acceptable to them while the designer/technical architect is trying to visualize a solution more palatable to his taste. The choice of "WSDL First" approach or "Java First" approach largely depends on whether we choose the business vision (WSDL) of the web service or whether we choose a Technical vision (Java) of the web service. If we try to please them both, we may adopt to bridge the gap and "meet in the middle". This is definitely a great solution but a tedious one sing satisfying both business and technical viewpoint often has ramifications on the kind of technologies and the stack structure that we may use.

Note: The above article is based squarely on the design of server side components. When designing a client side more often than not we will go for a WSDL First since we would be consuming a web service and not creating one.

No comments:

Post a Comment