Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A simple question

 
Neha Mohit
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can we expose the object class itself in a webservice method


thanks in advance
 
Neha Mohit
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Peer Reynders
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 132
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic