File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Services and the fly likes Web service return complex data type vs.  XML string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Web service return complex data type vs.  XML string" Watch "Web service return complex data type vs.  XML string" New topic
Author

Web service return complex data type vs. XML string

Ricky Murphy
Ranch Hand

Joined: Oct 16, 2007
Posts: 31
Trying to compare the advantage of a web service method returning complex type or xml string in different situations.

It looks more generic to return a xml string to represent the complex type object, but if so, what is the need to make a web service return a complex data type (i.e. a pojo, a bean). I know there must be some sort of judgment (depends on the use case) to pick either one, what is your standards to determine which approach to choose?

Thank you

-Rick
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2906
Originally posted by Ricky Murphy:
Trying to compare the advantage of a web service method returning complex type or xml string in different situations.


For one thing a SOAP web service always returns XML (or MIME for attachments).

The client decides what to do with that XML. Often code-generation tools are used to generate the code to un-marshal the XML to a bean (which may look nothing like the original complex type on the server) for expediency sake. However using static stubs is "static binding" which is a form of tight-coupling. Prodding the result XML with some XPath expressions to extract just the minimum amount of data required is a more loosely coupled approach (which requires more effort because it requires more manual coding). Finally the client could decide to simply keep the XML as is, especially if it uses an XML-based infrastructure, though it's likely that it would run an XSLT transformation on it to change it to a more suitable format for its domain.


"Don't succumb to the false authority of a tool or model. There is no substitute for thinking."
Andy Hunt, Pragmatic Thinking & Learning: Refactor Your Wetware p.41
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Web service return complex data type vs. XML string
 
Similar Threads
return complex types
Need to return a ValueObject from a Service .
Better way to return XML document
Rest web service and normal servlet
difference between complex type and XML type ?