wash_out gem 访问 soap_config 方法时出错

wash_out gem error accessing soap_config method

我无法从使用 wash_out gem 创建的 SOAP 服务获得 xml 响应。现在我只想要一个将整数转换为字符串的 soap 响应,就像在 washout 示例代码中所做的那样。知道我在这里做错了什么吗?

我的控制器代码是:

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

服务器响应以下 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>

soap 客户端正在发送以下消息:

<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>

服务器因以下内部错误而失败:

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'

为了详细说明我的 rails 环境,我还包括了我的 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

这意味着wash_out发现控制器有误。

gem源码(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

确保 gem 找到的控制器是正确的。

您的控制器代码是:

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

正确的cofing/routes.rb代码为:

wash_out "Api::Accounts"

以上代码适用于 0.9.2 版本。

版本0.10.0,你可以这样做:

wash_out :accounts, module: "Api"