Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Basic question about what a WS can return.

 
Darrin Smith
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?
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • 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!
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!