Savon

Savon can be installed as a gem via:

$ gem install savon

Dependencies

builder >= 2.1.2
crack >= 0.1.4

Warning

To use this heavy metal library, you should be familiar with SOAP, WSDL and tools like soapUI.

Instantiate Savon::Client

Instantiate Savon::Client, passing in the WSDL of your service.

client = Savon::Client.new "http://example.com/UserService?wsdl"

The WSDL

You can find out about the SOAP actions available on the webservice by using the WSDL object.

client.wsdl.soap_actions.keys
=> [:get_all_users, :get_user_by_id, :user_magic]

Find out more about the WSDL object.

Calling a SOAP action

Now, assuming your service applies to the default Options, you can just call any available SOAP action.

response = client.get_all_users

Savon lets you call SOAP actions using snake_case, because even though they will propably be written in lowerCamelCase or CamelCase, it just feels much more natural.

The SOAP object

Pass a block to the SOAP request which expects a single variable and Savon will hand you the SOAP object to specify various SOAP-related options.

response = client.get_user_by_id { |soap| soap.body = { :id => 666 } }

Learn more about the SOAP object.

The WSSE object

Pass a block to the SOAP request which expects two variables and Savon will yield the SOAP and WSSE objects.

response = client.get_user_by_id do |soap, wsse|
  wsse.username = "gorilla"
  wsse.password = "secret"
  soap.body = { :id => 666 }
end

Learn more about the WSSE object.

The response

The response is wrapped in an object to give you various options of handling it. Take a look at the Response for more information.

HTTP errors and SOAP faults

Savon raises a Savon::SOAPFault in case of a SOAP fault and a Savon::HTTPError in case of an HTTP error. More information about Errors.

Logging

By default Savon logs each request and response to STDOUT. Specifying your own logger is as easy as it gets:

Savon::Request.logger = RAILS_DEFAULT_LOGGER

Read more about Logging.

RDoc and Wiki

Further information: Wiki and RDoc