SOAP request with Ruby

I had a hard time finding examples while trying to get code to test a SOAP service with Ruby. Therefore, I thought I would add an example to the Google code repository. In the end I didn't get this working, this is the final work of a developer named Jim Johnson. I got started down the road and Jim came along and finished it up.



require 'soap/element'
require 'soap/rpc/driver'
require 'soap/processor'
require 'soap/streamHandler'
require 'soap/property'

LOCALHOST_ENDPOINT = "http://localhost:8080/services/Service"
request_xml_string = 'xml...'
stream = SOAP::HTTPStreamHandler.new(SOAP::Property.new)

header = SOAP::SOAPHeader.new
body_item = SOAP::SOAPElement.new('getResponse', request_xml_string)
body = SOAP::SOAPBody.new(body_item)
envelope = SOAP::SOAPEnvelope.new(header, body)
request_string = SOAP::Processor.marshal(envelope)
request = SOAP::StreamHandler::ConnectionData.new(request_string)

resp_data = stream.send(LOCALHOST_ENDPOINT, request, 'getResponse')

puts "Got response:"
puts resp_data.receive_string