File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Services and the fly likes Returning an array of objects through a web service Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Returning an array of objects through a web service" Watch "Returning an array of objects through a web service" New topic
Author

Returning an array of objects through a web service

Dominic Debrincat
Greenhorn

Joined: Jan 14, 2012
Posts: 3
Hi
I created a web service which is working correctly, but I can't figure out how to pass objects through it. Here are my object classes:



And here is my web service method to query the database :



When I try to run the method it returns null.
If anyone has any ideas they would be greatly appreciated. Of even a better way then passing them as objects, I am open to ideas.

Thanks.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
If the "objects" you want to return are just holders for some strings, why not define your service as returning sets of strings?

Actually the most important questions have to do with the potential clients of this web service. What do you expect clients to be looking for? What software will they be running?

Is this a SOAP or RESTful style service?

Bill
Dominic Debrincat
Greenhorn

Joined: Jan 14, 2012
Posts: 3
This is a SOAP style service

The objects are just holders of some string, would it be easier to return sets of Strings, I had to set them to objects as it is part of the requirements of my assignment but returning at least a string will be a start.

As for the clients, I would need the client to be able to view the records in the database and scroll through them, then eventually update the database. I have to create two clients using two different software, java (netbeans) and .net (VS 10)


EDIT

I tried to return the Strings I finally got a value apart from null, thanks for that suggestion. Although i'm only receiving the last record in the database, I guess thats why we have to save them in an array of objects to return all the records.
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1031
    
    5

Dominic

I have to ask why you are returning an instance of java.lang.Object to your clients? What do you expect them to do with it, except for a nasty hardcoded cast.

How is your WSDL defined?
Dominic Debrincat
Greenhorn

Joined: Jan 14, 2012
Posts: 3
I set it to java.lang.Object as I thought since I was returning an object I had to set it to that.

As for the WSDL i have not altered it, I'm testing the web service over local host.
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1031
    
    5

Can you show us your WSDL listing?

Usually a SOAP web service will have its own defined types for a client to consume but these will not normally be java.language.Object.
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
I would recommend creating a Java bean class that contains fields for all the data that is to be returned. Use this return type when declaring the return type of the methods to be exposed in the web service.
This because:
1. Your code will be easier to understand.
2. Such a Java bean will correspond to a XML type, resulting in an element (with contents) in the response XML. If there, in the future, is a need for introducing a new version of the return data, this will be significantly easier with the mentioned construct.
Best wishes!


My free books and tutorials: http://www.slideshare.net/krizsan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Returning an array of objects through a web service