Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

when to return a value directly instead of returing xml

 
Monica Shiralkar
Ranch Hand
Posts: 861
1
  • Mark post as helpful
  • send pies
  • 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
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • 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: 861
1
  • Mark post as helpful
  • send pies
  • 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.

 
Vishwanathan Nagarajan
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • 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: 861
1
  • Mark post as helpful
  • send pies
  • 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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic