Green Acorn


Creating a Ruby SOAP Client

In a previous post, I created this web service in PHP (view the post here). In order to create a client in Ruby, I’ll need to install a Ruby Gem called Savon. Savon is a SOAP client library for Ruby and will allow me call the PHP based web service via Ruby code.

Install Savon

sudo gem install savon

Using Savon

Create a file called soap.rb and copy and paste the below code:

require 'savon'

client = Savon.client(wsdl: '')

# => food_get_food

# call the 'getFood' operation
response =, message: {type: 'Main'})

puts response.body[:food_get_food_response][:return]
# Curry

Firstly, I include the Savon library by requiring it at the top of the file. Next I create a client object and define the WSDL. The WSDL file was created in the previous post.

Once the client is configured, I can use the “operations” method to see which methods are available from the web service. If you look at the PHP SOAP server from the previous post, you will notice there is a class called “food” and a method called “getFood“. Savon has converted this into a Ruby proxy method called “food_get_food“.

You can call the web service methods by using Savon’s “call” method. The first argument is the method name as a symbol, and the second argument are the RPC arguments.

Finally, you can view the response by calling response.body.

To test, navigate to the folder where you saved soap.rb and type the following in the command line:

ruby soap.rb

My main dish was “Curry”!

Posted in: Ruby, Web Services

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>