File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Services and the fly likes How to return Object as a Response (Please Reply) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "How to return Object as a Response (Please Reply)" Watch "How to return Object as a Response (Please Reply)" New topic

How to return Object as a Response (Please Reply)

rushikesh kale
Ranch Hand

Joined: Jan 25, 2005
Posts: 41


I am trying to create webservice method which will return particular (Employee) object as a response.
I wrote following method to implement that :

I deployed this web service on a Glassfish server (in netbean6.0.1) successfully.

But when i try to call this method via web service client, I am not able to
give a argument to above function.
My Client calling code is as follows:

where argEmpIfo is of type List<org.beans.Employee> which is present at different web service.
Even though both Employee Classes have same strucure, I am getting incompatible type error.

So, Is there any other logic to return Object from a web service operation?

Please reply to this post, I am very new to web service development and I desperately looking for right direction to create a web servicce for my Company.
Grady Jamyson
Ranch Hand

Joined: Aug 04, 2002
Posts: 42
I actually have the same question as you do. I have my own type in the server side, but I copy it into the client.

I can refer to the return type in the client code, but I have compiler error when building the client codes using Netbeans 6.1. I am still trying to figure it out.
Peer Reynders

Joined: Aug 19, 2005
Posts: 2933
In a tool-based environment like netbeans you usually go through the following steps with the "contract last" approach:
  • Generate the SOAP request and response format from the server based methods and types and capture them in the WSDL web services contract.
  • Generate client types from the SOAP request and response formats described the WSDL.

  • That is serverType -> WSDL -> clientType

    As a result the client types are often different from the server types. If you have a true object (data + behavior) on the server side as an operation parameter then that object will simply become a "data transfer object" style bean (data + getter + setters without any business logic) on the client side.

    Web services aren't internet EJB!
    The web service provider and web service consumer simply exchange messages that contain semi-structured data - they do not exchange full-blown (java) objects.

    If you already have classes on the client side that you wish to use then you often have to write all the XML (un)marshalling code yourself. Axis2 offers the option of using JiBX in combination with the WSDL-to-Java code generation so that you only have to provide the XML mapping configuration.

    Originally posted by rushikesh kale:
    I desperately looking for right direction to create a web servicce for my Company.

    Well, then don't get entranced by the web service magic pixie dust and I suggest that you start looking at this type of information:

    Why Contract First?
    "Item 43: Recognize the object-hierarchical impedance mismatch" in Effective Enterprise Java: Ch.5: State Management (PDF)
    Example of Web Services
    Starting Out
    jaxb & object graphs
    Going crazy with webservices and Hibernate
    [ April 29, 2008: Message edited by: Peer Reynders ]
    I agree. Here's the link:
    subject: How to return Object as a Response (Please Reply)
    It's not a secret anymore!