This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

sending back XML from the service provider  RSS feed

 
Dan Walin
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a web service called "CMR" that does a lookup (db2) and returns an object called CMRAll to the service requester. This object just contains all the fields pulled in the query. This works well and the service requester can access any of the fields in the CMRAll object as it needs to. So far so good. Now, however, I'm being asked to return a String of the XML of this data back to the requester. When I run my tests and look at the TCPIP monitor in Rational, the service provider sends the soap message (xml format) back to the requester that contains all the elements that are needed and the requester gets it as the CMRAll object. My question is: Is there a way for the service requester to actually see the soap message and use it in it's "native format"? The process seems to be "provider creates CMRAll object, it's transported in a soap message in xml format and the requester receives it and sees it as a CMRAll object". I'm wondering if the requester can actually see it the way the soap message has it formatted? As you may be able to tell I'm very new at Web Services so it won't bother me if I get any critical replies that can help.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way for the service requester to actually see the soap message and use it in it's "native format"?


Sure - but it depends on how the requester is generating the request.

If the requester is using some SOAP client toolkit, you are stuck with whatever the toolkit provides.

If the requester is controlling the request at a more basic level (say with HttpURLConnector or even sockets) then getting the character stream representing the SOAP reply should be easy.

Bill
 
Dan Walin
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This runs under Websphere and I think the handling of the soap message is done at a level that my code does not know about or care about, so I changed my approach to this:

I found that when the servlet gets the CMRAll object back from the service, it can use recursion to ask the object what fields it has and what are the values in the fields. Then, in a little loop, the servlet creates the xml. If the fields were to ever change, the servlet would never need to be altered, it would automatically know the field names and values that come back.

method that uses this concept:



This seems to work well.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!