• 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

when to return a value directly instead of returing xml

 
Ranch Hand
Posts: 2925
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I read that web services return response in xml format. But suppose I create a stock web service and calling its getQuote method returns directly the value, then how are we able to get the value directly without parsing the xml.

From this below is my understanding.Please verify whether it is correct:

When we do coding for web service class, from the web service method we should return a value (not xml) If it is just a single value say price=80 then we return just 80 and no xml
Whereas If we have to return various things such as price,time,date etc then instead of returning value we return an xml from the web service return value. E.g and xml with
<price></price>
<time>8000</time>
<date>12122011</date>


Please tell whether my understanding and conclusion is correct.

thanks
 
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
There is a very clear distinction that needs to be drawn between SOAP and REST style "web services".

SOAP is a messaging API where the messages must always be valid XML according to strict rules

REST is an architectural "style" where the messages are always HTTP request and response with content that can be anything.

See the many references on the Ranch FAQ page.

Bill
 
Monica Shiralkar
Ranch Hand
Posts: 2925
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks.I am talking about SOAP based web services. Suppose there is a web service method we have to implement say getStockQuote. (which would return stock value) Then in the return statement we can directly write return someValue say return 80 or we need to return an XML with this value only?
I think XML should be returned when there are a lot of parameters to be returned not just the stockPrice.For just the stock price why return the xml and later ask client to parse it.

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

For just the stock price why return the xml and later ask client to parse it.



If the response from the Web Service is just bundle of atomic values to be displayed in a client like browser, you can instead have a JSON based web service instead of a XML based web service. This will reduce the hassle of parsing the XML at client side since JSON could be easily parsed in Javascript.


-Vishwa
 
Monica Shiralkar
Ranch Hand
Posts: 2925
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

If the response from the Web Service is just bundle of atomic values to be displayed in a client like browser, you can instead have a JSON based web service instead of a XML based web service. This will reduce the hassle of parsing the XML at client side since JSON could be easily parsed in Javascript.




thanks but actually I am not talking for JSON. I am rather talking about plain text. Suppose web service is just getStockPrice method which give stock price so instead of JSON or XML why not return directly value


from the return statement of method why not just write instead of returning an XML or JSON. I tried this and it works.No need of parsing but I was surprised because I had read that response should be XML but how come plain text is working.

 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic