Search code examples
ruby-on-railsrubyweb-servicessoapwash-out

wash_out gem error accessing soap_config method


I'm having trouble getting an xml response from my SOAP service created using the wash_out gem. For now I just want a soap response that converts integer to string as done in the washout example code. Any ideas what I'm doing wrong here?

My controller code is:

soap_service namespace: 'http://localhost:3000/api/accounts/wsdl'
soap_action "get_new_account",
          :args   => :integer,
          :return => :string
def get_new_account
render :soap => params[:value].to_s
end

The server responds with the following rpc wsdl:

<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://localhost:3000/api/accounts/wsdl" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="api_accounts" targetNamespace="http://localhost:3000/api/accounts/wsdl">
<types>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://localhost:3000/api/accounts/wsdl"></schema>
</types>
<portType name="api_accounts_port">
<operation name="get_new_account">
<input message="tns:get_new_account"/>
<output message="tns:get_new_account_response"/>
</operation>
</portType>
<binding name="api_accounts_binding" type="tns:api_accounts_port">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="get_new_account">
<soap:operation soapAction="get_new_account"/>
<input>
<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost:3000/api/accounts/wsdl"/>
</input>
<output>
<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost:3000/api/accounts/wsdl"/>
</output>
</operation>
</binding>
<service name="service">
<port name="api_accounts_port" binding="tns:api_accounts_binding">
<soap:address location="http://localhost:3000/api/accounts/action"/>
</port>
</service>
<message name="get_new_account">
<part name="value" type="xsd:int"/>
</message>
<message name="get_new_account_response">
<part name="value" type="xsd:string"/>
</message>
</definitions>

The soap client is sending the following message:

<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
    <Body>
        <get_new_account xmlns="http://localhost:3000/api/accounts/wsdl">
            <value>123</value>
        </get_new_account>
    </Body>
</Envelope>

The server fails with the following internal error:

Started POST "/api/accounts/action" for ::1 at 2016-04-22 11:29:10 -0400

NoMethodError (undefined method `soap_config' for AccountsController:Class):
  wash_out (0.9.2) lib/wash_out/router.rb:18:in `parse_soap_action'

To detail my rails environment I also include my Gemfile:

source 'https://rubygems.org'

ruby '2.3.0'
#ruby-gemset=washout

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.2'
#ruby-gemset=washout

gem 'therubyracer'
# Use sqlite3 as the database for Active Record
#gem 'sqlite3'

# Use SCSS for stylesheets
gem 'bootstrap-sass', '~> 3.3.6'
gem 'sass-rails', '>= 3.2'
gem 'sprockets-rails'

# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
gem 'utf8_enforcer_workaround'


gem 'autoprefixer-rails', '>= 5.2.1'
gem 'pg'

# Use jquery as the JavaScript library
gem 'jquery-rails'

# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
# gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Unicorn as the app server
# gem 'unicorn'

# Wash Out Soap Service
gem 'wash_out', '0.9.2'

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug'
  gem 'annotate'
  gem 'rspec-rails'
  gem 'factory_girl_rails'

  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
end

group :development do
  # Access an IRB console on exception pages or by using <%= console %> in views
  gem 'web-console', '~> 2.0'
  gem 'capistrano'
  gem 'capistrano-bundler'
  gem 'capistrano-passenger'
  gem 'capistrano-rails'
  # gem 'capistrano-rvm' 
end

group :test do 
  gem 'faker', '1.4.2'
  gem 'capybara'
  gem 'selenium-webdriver'
  gem 'database_cleaner'
  gem 'guard-rspec'
  gem 'launchy'
end

Solution

  • This means that the wash_out found the controller is wrong.

    The gem source code(wash_out-0.9.2/lib/wash_out/router.rb):

    class Router
      def initialize(controller_name)    # controller_name = "accounts"
        # @controller_name = AccountController
        # the controller maybe incorrect.
        @controller_name = "#{controller_name.to_s}_controller".camelize
      end
      ...
    end
    

    Ensure that the gem found the controller is correct.

    Your controller code is:

    class Api::AccountsController < ApplicationController
      soap_service namespace: 'http://localhost:3000/api/accounts/wsdl'
      soap_action "get_new_account",
          :args   => :integer,
          :return => :string
      def get_new_account
        render :soap => params[:value].to_s
      end
    end
    

    The right cofing/routes.rb code is:

    wash_out "Api::Accounts"
    

    The above code is working in version 0.9.2.

    Version 0.10.0, you can do this:

    wash_out :accounts, module: "Api"