aspose file tools*
The moose likes Web Services and the fly likes when to return a value directly instead of returing xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "when to return a value directly instead of returing xml" Watch "when to return a value directly instead of returing xml" New topic
Author

when to return a value directly instead of returing xml

Monica. Shiralkar
Ranch Hand

Joined: Jul 07, 2012
Posts: 644
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

Joined: Mar 22, 2000
Posts: 12784
    
    5
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

Joined: Jul 07, 2012
Posts: 644
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

Joined: Jan 28, 2009
Posts: 37
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


MCP, SCJP 1.4, SCWCD 1.4, SCBCD 5.0, SCDJWS 1.4
Monica. Shiralkar
Ranch Hand

Joined: Jul 07, 2012
Posts: 644
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.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: when to return a value directly instead of returing xml