Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Returning an array of objects through a web service

 
Dominic Debrincat
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic