• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Web Service (web method) String return type

 
Ranch Hand
Posts: 541
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
This will take every ounce of my mental strength! All for a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic