tags:

views:

262

answers:

1

I have set up a soap4r client for a web service, and it's working fairly well. We're using it to send data from one database to another (don't bother asking about that... I know it's not optimal), but we're not entirely sure the mapping is correct, so it's often very handy to get the XML that a particular record would generate.

Of course, that's possible - if you set $DEBUG, soap4r will supply you with a nice dump of the XML going over the wire. You can even set the "device" (file) that you would like to send it to.

However, I'd like to be able to get the XML that it's going to generate without having to actually call the web service.

Is there a way to do this? Grepping around, I've found a variety of obj2soap and similar methods, but none of them seems to be quite the one I want.

+1  A: 

An indirect answer: you might want to look at handsoap. It's faster and tries to be more Ruby-like. It uses builder-style XML generation - but you have to generate everything yourself. It's more like a toolbox to write your client in a clean way. This way you know what was generated (and can inspect it easily).

Another option is to set $DEBUG and restore it afterwards:

$REMEMBER_DEBUG_STATE = $DEBUG
$DEBUG = true
# call soap (and have your XML generated)
$DEBUG = $REMEMBER_DEBUG_STATE

This could be extracted to a nice function like this:

def with_debug_output
  remember = $DEBUG
  $DEBUG = true
  yield if block_given?
  $DEBUG = remember
end

and then use it:

with_debug_output do
  # call soap
end
bb
I'm not interested in changing horses midstream, so I need to stick with soap4r.I know about $DEBUG, but I don't want to call the service; I just want to grab the XML that would have been generated.
David N. Welton