Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How do I return simple object via web services  RSS feed

 
avseq anthoy
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the sample code listed below,I set return type as String


How do I set parameter that I can return simple object like Person



The completed code list below.
Thanks in advance.
 
Balaji Loganathan
author and deputy
Bartender
Posts: 3150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to use beam mapping concept of Axis.
An article on how to do this is available at http://radio.javaranch.com/balajidl/2006/03/22/1143041392434.html
 
avseq anthoy
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Excuse me , I don't have to write wsdd or any other xml document to deploy my web service , because myeclipse or other IDE tools do these for me.
I wanna know about can I modify the paramters in the code so that I can get a simple object that web services return to me.

Thanks in advance.
 
Watsh Rajneesh
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you already have a WSDL mentioning Person type as return type of web method then all you should be doing is :
QName QNAME_TYPE_PERSON = new QName("<Person namespace>", "PersonType");
call.setReturnType(QNAME_TYPE_PERSON);

example: <person namespace> as defined by your service wsdl could be http://examples.org/SayHello and PersonType could be a complex type in the wsdl. Complete WSDL as i see your problem is at the end of this reply.

and you cast the result to Person type:
Person person = (Person)call.invoke(params);

You will need to have the Person java bean class defined at client.

I too am learning webservices for now.. so this is no expert comment. Please treat this reply kindly and tell me if i am mistaken in understanding your question.

The Person class can be of the kind:


 
Watsh Rajneesh
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use WSDL-to-Java tools to generate support classes, even if using the dynamic proxy or DII approach.

For example, just to compile the client code, the developer must understand the WSDL for a service and generate by hand Java classes that match the parameter and return types defined in the WSDL document or, in the case of a dynamic proxy, the client-side representation of the service endpoint interface. These classes must be set up properly so that the JAX-RPC runtime can match SOAP message types to the corresponding Java objects.

Above comments are excerpted from chapter 5 of Blueprints Webservices book.

So you can either hand write the Person class or better yet have the WSDL2Java generate that for your DII client.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!