Ruby + Savon + Soap

Introduction

Savon is a SOAP client library for Ruby. It’s goal is to provide a lightweight and easy to use alternative to soap4r. If you’re starting to use Savon, please make sure to read this guide and make yourself familiar with SOAP itself, WSDL documents and tools like soapUI.

Installation

$gem install savon

Runtime dependencies

  • Builder ~> 2.1.2
  • Crack ~> 0.1.8
  • HTTPI >= 0.7.5
  • Gyoku >= 0.1.1

Simple example

require 'rubygems'
require 'savon'
require 'rexml/document'
include REXML

client = Savon::Client.new do
  wsdl.document = "http://www.abc.com/service?wsdl"
end

response = client.request :man, :findDetailsById do
  soap.body = "
                         <id>7950801</id>
"
end
#puts response.to_xml

xmldoc = REXML::Document.new(response.to_xml)
currentDate = Time.new
filesuffix = currentDate.strftime("%Y%m%d%H%M%S")
resultfile_path = "result/response_" + filesuffix + ".xml"
file = File.new("#{resultfile_path}","w+")
XPath.each(xmldoc, "//return/*") do |e|
  file << e
end

Table Of Contents

Previous topic

Ruby + DBI + Sql Server + Windows

Next topic

Watir(Web automation testing in Ruby)

This Page