aspose file tools*
The moose likes Web Services and the fly likes A simple question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "A simple question" Watch "A simple question" New topic
Author

A simple question

Neha Mohit
Ranch Hand

Joined: Apr 25, 2006
Posts: 87
Can we expose the object class itself in a webservice method


thanks in advance
Neha Mohit
Ranch Hand

Joined: Apr 25, 2006
Posts: 87
Originally posted by Neha Mohit:
Can we expose the object class itself in a webservice method


thanks in advance



I think we cannot ; because Object is not a serializable class and only those objects can be exposed in a webservice which are serializable.


Am i right
Alessandro Ilardo
Ranch Hand

Joined: Dec 23, 2005
Posts: 218
I have tried to return a custom class (which implements Serializable) on an exposed webservice method. It didn't work.

I am newbie too with webservices and it is not yet clear if we can use only data types specified by JAXB or custom classes as well.

Thanks
[ October 01, 2007: Message edited by: Alessandro Ilardo ]

trying to decode a woman mind....
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
You should only use classes that can be mapped to XML Schema types, as per the WSDL specification. That will ensure that your Java WS are interoperable with other WS developed using different technologies.

So, using just any old Java class (serializable or not) won't do, unless you have written a custom serializer/deserializer that creates XML from it.


Ping & DNS - my free Android networking tools app
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
Originally posted by Neha Mohit:
Can we expose the object class itself in a webservice method

I wouldn't recommend it and would strongly advise against it. See some of my various diatribes:

jaxb & object graphs
Shall I call a web service with Object type object
Going crazy with web services and Hibernate (some general web service design advice)
why web services?
Beginning Web Services
web services vs existing technologies
Query on Interoperability
Yohan Liyanage
Ranch Hand

Joined: Aug 17, 2007
Posts: 132

You can use the Java Beans XML Encoder/Decoder API to produce a XML file which represents your Java Object, if it meets the Java Beans specification. This is similar to normal Serilization with java.io.Serializable.

But please note that your class should adhere to Java Beans requirements. XML Encoder/Decoder API can be found at java.beans.*;

Other option is to use a JAXB Implementation. But in this case, you will have to write a XSD (XML Schema Definition) and use the JAXB Binding Compiler to build the classes from the XSD. This article about JAXB 2.0 gives the basics of JAXB 2.0.

Once you got the XML from the object, you can easily return the XML from your Web Service method.

(You will need the class file at the client-side to De-Serialize the XML).
[ October 07, 2007: Message edited by: Yohan Liyanage ]

Yohan Liyanage
http://blog.yohanliyanage.com
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: A simple question