This week's giveaway is in the JDBC forum.
We're giving away four copies of Java Database Connections & Transactions (e-book only) and have Marco Behler on-line!
See this thread for details.
Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Basic question about what a WS can return.  RSS feed

 
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know that you are limited to certain types which you can return (primitives, String, Date, etc.) from a Web Service method, but I was wondering if there is any way around that (via extension, etc.).

What I'd like to do is create a class based on those types (some string, ints, doubles, etc.) and return that instead. Is there any way to do that?
 
Rancher
Posts: 43009
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the object is a bean (i.e., there are appropriately named getters and setters for all the fields), you could use the java.bean.XMLEncoder and XMLDecoder to create an XML fragment that can be transferred over WS. Some SOAP engines (e.g. Axis) even have built-in serializers for beans, so you wouldn't have to do anything special in your code.

Alternatively, at the expense of cross-platform compatibility, you can use Java serialization to create a binary representation of the object. If you then base64-encode it, you should have no problems using it in SOAP.
 
Darrin Smith
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Ulf Dittmer:
If the object is a bean (i.e., there are appropriately named getters and setters for all the fields), you could use the java.bean.XMLEncoder and XMLDecoder to create an XML fragment that can be transferred over WS. Some SOAP engines (e.g. Axis) even have built-in serializers for beans, so you wouldn't have to do anything special in your code.

Alternatively, at the expense of cross-platform compatibility, you can use Java serialization to create a binary representation of the object. If you then base64-encode it, you should have no problems using it in SOAP.



Thanks!
 
Always look on the bright side of life. At least this ad is really tiny:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!