Rails:使用 Savon 请求 SOAP:无法处理请求

Rails: Request to SOAP using Savon: Unable to process request

出于学习目的,我正在尝试 gem Savon 从 GlobalWeather SOAP Web 服务获取信息。 http://www.webservicex.net/globalweather.asmx?WSDL

我能够连接到 API 并检索操作:

[:get_weather, :get_cities_by_country]

但是当我尝试调用传递消息时,我收到关于未传递参数的错误消息:

Savon::SOAPFault in CitiesController#index
(soap:Server) System.Web.Services.Protocols.SoapException: Server was unable 
to process request. ---> System.Data.SqlClient.SqlException: Procedure or 
function 'getWCity' expects parameter '@CountryName', which was not 
supplied. at WebServicex.GlobalWeather.GetCitiesByCountry(String 
CountryName) --- End of inner exception stack trace ---

我的控制器城市代码如下:

class CitiesController < ApplicationController
  def index
    @operations = client.operations
    @response = client.call(:get_cities_by_country,  message: { CountryName:"Spain" })
  end

  def client
    Savon.client(wsdl: 'http://www.webservicex.net/globalweather.asmx?WSDL')
  end
end

我认为问题可能与哈希消息如何根据文档转换为驼峰式大小写有关,因此我尝试使用全局选项 convert_request_keys_to :none 但没有发生任何不同。

class CitiesController < ApplicationController
  def index
    @operations = client.operations
    client = client do
      convert_request_keys_to :none 
    end
    @response = client.call(:get_cities_by_country,  message: { CountryName: "Spain" })
  end

  def client
    Savon.client(wsdl: 'http://www.webservicex.net/globalweather.asmx?WSDL')
  end
end

我明白了,它确实与 convert_request_keys_to 选项有关,但它应该在 Savon::client 调用中传递

def client
  Savon.client(wsdl: 'http://www.webservicex.net/globalweather.asmx?WSDL', convert_request_keys_to: :none)
end