I don't know what you have done so far.
deepak kukreja wrote:I want my web service to have methods which return Custom objects e.g. Employee, Project etc objects. I am using Axis2 with the ADB data binding.
This suggests that you created the web service yourself. Did you use
Java2WSDL to do that? I suspect that you had some Java methods that simply returned
java.lang.Objects which is how you ended up with the
{http://www.w3.org/2001/XMLSchema}anyType. That approach does not work the way that you hoped it would.
I used wsdl2java to create the stubs and call the stub method from the client program.
This suggests that there is already a WSDL in existence (possibly from
Java2WSDL) - you are just creating consumer stubs. This suggests that you are accessing an already existing web service - not creating one.
One thing that you have to understand is that the premise of web service interoperability is based on the fact that provider and consumer are exchanging semi-structured data in XML format -
not as platform dependent object representations (e.g. Java Objects). So when you use
Java2WSDL and then
WSDL2Java you will probably not get the Java Objects on the consumer side that you had on the provider side. The objects on the consumer side are merely "data containers" that contain the same data that was in the XML that went over the wire.
That is why
Contract first is considered a "Best Practice" in web service development. (See also the second half of
this post)
Develop an XML Schema that contains EmployeeType, ProjectType, etc. element definitions that hold the equivalent data of your Employee, Project objectsUse that XML Schema in the definition of you web service contract (WSDL)Use WSDL2Java to generate a service skeleton. This will also generate the ADB versions of EmployeeType, ProjectType etc.In your glue code between the service logic and the service skeleton code, put your Employee to EmployeeType (and back), etc. conversionsUse WSDL2Java to generate a consumer stub. Remember the consumer may not even be interested in your Employee and Project Objects, they may have their own. So typically one would write a wrapper around the consumer stub which would be responsible for the EmployeeType to Employee (and back) conversions. This basically relates to the Business Delegate and Remote Façade pattern.
With this approach
you should be able to avoid any manual handling of XML in your code - however you need to deal with XML in terms of the XML Schema and WSDL.