SOAP support (as a server) in Rails has deteriorated from version to version. In version 1.x, the rails were completed with
AWS . In version 2.x, AWS split into several forks that enthusiasts supported. Until version 3.x, in a stably operating version, AWS did not live. Ideologically, this attitude towards SOAP may or may not like it, but in real life we are surrounded by a great and terrible enterpris'om. And support for bilateral SOAP can be needed in any integration: from 1C to automated banking systems.
Instead of supporting even more (stillborn?) AWS forks for version 3, we wrote
WashOut .
The heme supports respond_to, focusing on the SOAP mime type, which itself registers. That is, you can make a controller that produces html equally well, json, and also responds to SOAP. At the same time, WashOut supports all standard Rails features, such as before_filter.
')
How to make it work?
Connect gem
Add
gem 'wash_out'
to your gemfile.
Expand the necessary controllers
In order not to clutter the address space, WashOut is not mixed into the ApplicationController. Therefore, for each controller where you want to use SOAP, the module must be connected independently.
Describe WSDL
The parameters of each method are described separately using the
soap_action method.
soap_action "concat", :args => { :a => :string, :b => :string }, :return => :string def concat render :soap => (params[:a] + params[:b]) end
An example with the generation of a SOAP error and a modified method name.
soap_action "AddCircle", :args => { :circle => { :center => { :x => :integer, :y => :integer }, :radius => :double } }, :return => [], :to => :add_circle def add_circle circle = params[:circle] raise SOAPError, "radius is too small" if circle[:radius] < 3.0 Circle.new(circle[:center][:x], circle[:center][:y], circle[:radius]) render :soap => nil end
Add routing
Routing is also prescribed for each controller (in our example, it is ApiController)
PROFIT!
This controller's WSDL is located at / api / wsdl (or / your_controller / wsdl). All other methods and paths SOAP will already find from it.
To test what works, you can use the Savon gem:
require 'savon' client = Savon::Client.new("http://localhost:3000/api/wsdl") client.wsdl.soap_actions
We want you for the OSS army!
In case of problems and / or development ideas, we are waiting for your
Issues and
Pull Requests on Github.
Thank.