wood burning stoves 2.0*
The moose likes Web Services and the fly likes Web Service (web method) String return type Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Web Service (web method) String return type " Watch "Web Service (web method) String return type " New topic
Author

Web Service (web method) String return type

Saurabh Pillai
Ranch Hand

Joined: Sep 12, 2008
Posts: 507
I have a question about best practices. Let's say I have a web method that returns employee id and employee name. Now, since I am new to Web Service,we( client(C#) and I(Java)) agreed upon a return type List<String> and String format is "employee id,employee name". All is well so far. Program runs and it does the job.

Now, the other day, I was having conversation about return type with another developer and she suggested the way I am returning the data is not right instead I should return String in XML format so the typical output may look like (here without formatting),

I argued that, in this case, you're returning more than 50% non-data(XML tags) to client which is unnecessary. And she argued back that in case of unobvious scenarios like, user does not have permission to access something or there is nothing to return but the error code or something went wrong on server i.e when you need to return something else other than actual data itself, XML string is helpful since you can insert <error> tag. And it's a valid argument so can somebody with good experience with Web Service shed some light here?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
The choice of XML as an output format has good and not so good implications:

Good:
Flexibility, if you decide to add new fields to the information returned, correctly written client software will not care and not even notice.
Documentation: with good tag names you will be able to understand what you were doing when you look at the project later.


NotSoGood:
Client side needs to parse XML - time consuming for huge data sets.
More bandwidth consumed - back in the days of 2400 baud dialup connections this might have been worrying, zipping an XML document can make a huge difference because of all the repeated tags.
Have to learn new tools - might actually be a plus depending on your employment goals

Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Web Service (web method) String return type